You've already forked postfixadmin
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:
@@ -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,20 +1544,16 @@ 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 {
|
$link = new PDO($dsn, null, null, $options);
|
||||||
$link = new PDO($dsn, null, null, $options);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($queries)) {
|
if (!empty($queries)) {
|
||||||
foreach ($queries as $q) {
|
foreach ($queries as $q) {
|
||||||
$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);
|
||||||
|
Reference in New Issue
Block a user