From the PHP docs as pointed out by @Funk Forty Niner.
https://secure.php.net/manual/en/mysqli.construct.php
Note:
OO syntax only: If a connection fails an object is still returned. To check if the connection failed then use either the mysqli_connect_error() function or the mysqli->connect_error property as in the preceding examples.
However, if you enable error reporting properly like you always should then if mysqli can't connect to the server it will throw an exception and return nothing. To do it properly enable error reporting before opening the connection:
<?php
error_reporting(E_ALL ^ E_WARNING);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$conn = new mysqli("bad", "bad", "so bad", "too bad, what then?");
// If an error occurred then the lines below will never be executed
//VVV - $conn will always be a valid mysqli object
$conn->set_charset('utf8mb4');
Contrary to what the PHP manual says, you should never check for mysqli connection errors manually!