Web: fix mysqli DB connection initialization

The mysqli class constructor returns an object even if the connection failed. The only way to find out about a connection failure is to call mysqli_connect_error() after the mysqli object was created.
See: http://php.net/manual/en/mysqli.construct.php#refsect1-mysqli.construct-examples
This commit is contained in:
Christian Beer 2015-11-18 10:44:46 +01:00
parent 3fc2d41f9a
commit 13a002cb8b
1 changed files with 4 additions and 0 deletions

View File

@ -41,6 +41,10 @@ class DbConn {
} else {
$this->db_conn = @new mysqli("p:".$host, $user, $passwd, $name, $port);
}
// mysqli returns an object even if the connection is not established
if (mysqli_connect_error()) {
return false;
}
global $mysqli;
$mysqli = $this->db_conn;
} else {