1
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2025-08-07 17:42:53 +03:00

Dont swallow database connection exceptions

This commit is contained in:
Felix Ableitner
2019-06-07 15:33:58 +02:00
parent 71402e9051
commit 5d0a587fe7

View File

@@ -1464,11 +1464,10 @@ EOF;
* @return \PDO * @return \PDO
*/ */
function db_connect() { function db_connect() {
list($link, $_) = db_connect_with_errors(); list($link, $error_text) = db_connect_with_errors();
unset($_);
if (!$link instanceof PDO) { if (!$link instanceof PDO) {
throw new Exception("Database connection failed"); throw new Exception("Database connection failed: $error_text");
} }
return $link; return $link;
@@ -1545,7 +1544,6 @@ function db_connect_with_errors() {
die("<p style='color: red'>FATAL Error:<br />Invalid \$CONF['database_type']! Please fix your config.inc.php!</p>"); die("<p style='color: red'>FATAL Error:<br />Invalid \$CONF['database_type']! Please fix your config.inc.php!</p>");
} }
try {
if ($username_password) { if ($username_password) {
$link = new PDO($dsn, Config::read_string('database_user'), Config::read_string('database_password'), $options); $link = new PDO($dsn, Config::read_string('database_user'), Config::read_string('database_password'), $options);
} else { } else {
@@ -1557,9 +1555,6 @@ function db_connect_with_errors() {
$link->exec($q); $link->exec($q);
} }
} }
} catch (PDOException $e) {
$error_text = 'PDO exception: '. $e->getMessage();
}
return array($link, $error_text); return array($link, $error_text);
} }