如何检测MySQLi初始化错误

In my website I am initializing DB connection using values read from config file, like this:

$this->mysqli = new mysqli($databaseInfo->MySQL_Host, $databaseInfo->MySQL_User, $databaseInfo->MySQL_Pass, $databaseInfo->MySQL_Db);

(for the record, values are being read from file properly and when everything is OK, db connection works just fine)

then I ask whether an error occurred during creating MySQLi object:

if (($this->mysqli!=null)&&($this->mysqli->errno == 0)) {

if no, then I want to set an error variable and handle it later in the code...I want this check only passes when no problem occurred...I thought "errno" variable provides sufficient check...

but apparently not, because regardless any error, I produce in config file, the code still jumps into "everything is fine" branch...obviously PHP produce a lot of warnings and finally it crashes on some fatal error related to the fact database doesn't work as expected

so my question is - how to set up this DB connection initial check properly to avoid such situation?

From PHP Manual, try this:

if (!$mysqli->error) {
   printf("Errormessage: %s
", $mysqli->error);
}

If using PHP OOP

  if ($mysqli->connect_error) {
  die('Connect Error: ' . $mysqli->connect_error);
  }
  ?>

If using procedural style PHP

 if (!$link) {
  die('Connect Error: ' . mysqli_connect_error());
  }
  ?>