I have a function to connect to a DB. I also check if that went through, however, when I fail it intentionally, it doesn't print out the errors in the if(!$db)
brackets.
function connectToDb(){
//Connect to a database
$db = new mysqli("localhost", "root", "", "vm_ski");
if(!$db){
echo "error: ConnectToDB failed";
printError("Could not connect to db: ".$db->error);
}
else{
echo "OK";
return $db;
}
}
It prints out the warning from PHP: Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO)
which I get. But why does it still print out "OK" in the else, shouldn't it call printError?