From 7f87c688558683f8874eb60b7eb8d07d2b5d4445 Mon Sep 17 00:00:00 2001 From: Shelvacu Date: Wed, 20 May 2020 16:45:50 -0700 Subject: [PATCH] Raise on DB errors; Fixes https://source.netsyms.com/Business/BinStack/issues/16 Removed `checkDBError` since it isn't used anywhere, and wouldn't be helpful. --- required.php | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/required.php b/required.php index b81e8b8..ad6b0df 100644 --- a/required.php +++ b/required.php @@ -106,7 +106,10 @@ try { 'server' => $SETTINGS['database']['server'], 'username' => $SETTINGS['database']['user'], 'password' => $SETTINGS['database']['password'], - 'charset' => $SETTINGS['database']['charset'] + 'charset' => $SETTINGS['database']['charset'], + 'option' => [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION + ] ]); } catch (Exception $ex) { //header('HTTP/1.1 500 Internal Server Error'); @@ -145,23 +148,6 @@ function dieifnotloggedin() { } } -/** - * Check if the previous database action had a problem. - * @param array $specials int=>string array with special response messages for SQL errors - */ -function checkDBError($specials = []) { - global $database; - $errors = $database->error(); - if (!is_null($errors[1])) { - foreach ($specials as $code => $text) { - if ($errors[1] == $code) { - sendError($text); - } - } - sendError("A database error occurred:
" . $errors[2] . ""); - } -} - function redirectIfNotLoggedIn() { global $SETTINGS; if ($_SESSION['loggedin'] !== TRUE) {