From c71dd25afa6c0728f68c4eb7704dd7b5a12c3d3f Mon Sep 17 00:00:00 2001 From: hawk Date: Sat, 9 Feb 2019 18:47:45 +0500 Subject: [PATCH] fix setup db_connect_with_errors PDO exceptions were not caught --- functions.inc.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index a6de1010..03bdfc74 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1495,18 +1495,22 @@ function db_connect_with_errors() { die("

FATAL Error:
Invalid \$CONF['database_type']! Please fix your config.inc.php!

"); } - if ($username_password) { - $link = new PDO($dsn, Config::read_string('database_user'), Config::read_string('database_password'), $options); - } else { - $link = new PDO($dsn, null, null, $options); - } - - if (!empty($queries)) { - foreach ($queries as $q) { - $link->exec($q); + try { + if ($username_password) { + $link = new PDO($dsn, Config::read_string('database_user'), Config::read_string('database_password'), $options); + } else { + $link = new PDO($dsn, null, null, $options); } - } + if (!empty($queries)) { + foreach ($queries as $q) { + $link->exec($q); + } + } + } catch (PDOException $e) { + $error_text = 'PDO exception: '. $e->getMessage(); + error_log($error_text); + } return array($link, $error_text); }