diff options
author | Andrew Dolgov <[email protected]> | 2017-12-10 09:27:07 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2017-12-10 09:27:07 +0300 |
commit | 83a052f1fa36e6bcebc6b6ee1ba6cfc9d9f480d0 (patch) | |
tree | c714a6714b9524daf4e86c6e43d7142b830c4c12 | |
parent | f8db5bb4db45f7e867a7f1e29ef58e1fd1473edc (diff) |
pdo_connect: catch exception on create
-rw-r--r-- | classes/db.php | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/classes/db.php b/classes/db.php index b6320944b..96a888275 100644 --- a/classes/db.php +++ b/classes/db.php @@ -54,12 +54,12 @@ class Db $db_port = defined('DB_PORT') && DB_PORT ? ';port=' . DB_PORT : ''; $db_host = defined('DB_HOST') && DB_HOST ? ';host=' . DB_HOST : ''; - $this->pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port, - DB_USER, - DB_PASS); - - if (!$this->pdo) { - print("Error connecting via PDO."); + try { + $this->pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port, + DB_USER, + DB_PASS); + } catch (Exception $e) { + print "<pre>Exception while creating PDO object:" . $e->getMessage() . "</pre>"; exit(101); } |