Skip to content

Commit 525dc21

Browse files
committed
Correctly handle mysql connection errors
1 parent 09f36df commit 525dc21

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

MysqliDb.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ public function connect()
210210
if (empty ($this->host))
211211
die ('Mysql host is not set');
212212

213-
$this->_mysqli = new mysqli ($this->host, $this->username, $this->password, $this->db, $this->port)
214-
or die('There was a problem connecting to the database');
213+
$this->_mysqli = new mysqli ($this->host, $this->username, $this->password, $this->db, $this->port);
214+
if ($this->_mysqli->connect_error)
215+
throw new Exception ('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error);
215216

216217
if ($this->charset)
217218
$this->_mysqli->set_charset ($this->charset);

0 commit comments

Comments
 (0)