0

here is my code (the database don't need password, but i intentionally added it to create the error)

<?php
$connection = mysqli_connect("localhost", "root", "null", "db") or die("Connection failed");
/*
if($connection = mysqli_connect("localhost","root","null","db")){
    print "Hello";
} else {
    print "Connection failed";
}
*/

?>

when the page load it show only error handle and don't execute the die function

  • 2
    Because it's *fatal*? – Your Common Sense Jul 26 '22 at 16:01
  • 2
    mysqli_connect() only returns false if you're _not_ in exception mode, and exception mode is the default. If you want to enable true/false mode so that this `or` technique works, then you have to call [`mysqli_report(MYSQLI_REPORT_ERROR)`](https://www.php.net/manual/en/function.mysqli-report.php) first. (But note, you'll _still_ get a warning. So... just use exception mode with try/catch instead of this `or` technique.) – Alex Howansky Jul 26 '22 at 16:05
  • @user19626532 what you are getting is a *correct* behavior, while your die() is NOT. Just follow the answer linked at the top – Your Common Sense Jul 26 '22 at 16:11

0 Answers0