From 83a052f1fa36e6bcebc6b6ee1ba6cfc9d9f480d0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 10 Dec 2017 09:27:07 +0300 Subject: [PATCH] pdo_connect: catch exception on create --- classes/db.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/classes/db.php b/classes/db.php index b6320944..96a88827 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 "
Exception while creating PDO object:" . $e->getMessage() . "
"; exit(101); }