The [..] or die()
construct leads to funny behaviour in conjunction with the return statement: The whole thing is interpreted as a boolean expression.
And because new mysqli
will never be false, the "die" is never processed, and thus, your function returns true
instead of a newly created instance of mysqli
.
If you still would like to use or die()
, do this:
$result = new mysqli($host, $user, $pwd, $db) ;
if (!$result) die ("Can't open database.");
return $result;