From 5d0a587fe73fb43af07acc0b5355cec1cc67072f Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 7 Jun 2019 15:33:58 +0200 Subject: [PATCH] Dont swallow database connection exceptions --- functions.inc.php | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index 38d8b79c..aa5e31c1 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1464,11 +1464,10 @@ EOF; * @return \PDO */ function db_connect() { - list($link, $_) = db_connect_with_errors(); - unset($_); + list($link, $error_text) = db_connect_with_errors(); if (!$link instanceof PDO) { - throw new Exception("Database connection failed"); + throw new Exception("Database connection failed: $error_text"); } return $link; @@ -1545,20 +1544,16 @@ function db_connect_with_errors() { die("

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

"); } - 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 ($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); - } + if (!empty($queries)) { + foreach ($queries as $q) { + $link->exec($q); } - } catch (PDOException $e) { - $error_text = 'PDO exception: '. $e->getMessage(); } return array($link, $error_text);