From 5db2ed6d37ecf86e3d1460e530d09f58d8717d3c Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 9 Sep 2014 02:52:24 +0200 Subject: [PATCH] Mask database connection error --- code/web/private_php/ams/autoload/dblayer.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/code/web/private_php/ams/autoload/dblayer.php b/code/web/private_php/ams/autoload/dblayer.php index c3ffdb403..d14e48e84 100644 --- a/code/web/private_php/ams/autoload/dblayer.php +++ b/code/web/private_php/ams/autoload/dblayer.php @@ -65,21 +65,22 @@ class DBLayer { } else { $dsn = "mysql:"; $dsn .= "host=" . $cfg['db'][$db]['host'] . ";"; - $dsn .= "dbname=" . $cfg['db'][$db]['name'] . ";"; // Comment this out when using the cache + // $dsn .= "dbname=" . $cfg['db'][$db]['name'] . ";"; // Comment this out when using the cache $dsn .= "port=" . $cfg['db'][$db]['port'] . ";"; $opt = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - PDO::ATTR_PERSISTENT => true, + // PDO::ATTR_PERSISTENT => true, PDO::ATTR_TIMEOUT => 5 ); $PDOCache[$this->host] = array(); try { $this->PDO = new PDO($dsn, $cfg['db'][$db]['user'], $cfg['db'][$db]['pass'], $opt); - } catch (Exception $e) { - $PDOCache[$this->host]['exception'] = $e; - throw $e; + } catch (PDOException $e) { + $exception = new PDOException("Failed to connect to the '" . $db . "' database server", $e->getCode()); + $PDOCache[$this->host]['exception'] = $exception; + throw $exception; return; } $PDOCache[$this->host]['pdo'] = $this->PDO;