From a816b73f66cd80fb48986b258226971529170615 Mon Sep 17 00:00:00 2001 From: Phyks Date: Sat, 30 Aug 2014 22:29:46 +0200 Subject: [PATCH] Try / catch MySQL connection --- inc/MysqlConnector.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/inc/MysqlConnector.php b/inc/MysqlConnector.php index b250c45..ee7fae9 100644 --- a/inc/MysqlConnector.php +++ b/inc/MysqlConnector.php @@ -9,8 +9,12 @@ class MysqlConnector { } public function connect() { - $this->connection = new PDO('mysql:host='.MYSQL_HOST.';dbname='.MYSQL_DB, MYSQL_LOGIN, MYSQL_PASSWORD); - $this->connection->query('SET NAMES utf8'); + try { + $this->connection = new PDO('mysql:host='.MYSQL_HOST.';dbname='.MYSQL_DB, MYSQL_LOGIN, MYSQL_PASSWORD); + $this->connection->query('SET NAMES utf8'); + } catch (Exception $e) { + exit ('Unable to access database.'); + } } public function disconnect() { @@ -22,9 +26,9 @@ class MysqlConnector { } public static function getInstance() { - + if (self::$instance === null) { - self::$instance = new self(); + self::$instance = new self(); } return self::$instance; }