I seem to have a problem that others have reported but the answers provided in other threads do not work in my case. I have code to connect to my db and it works fine, I can use it to connect and insert rows in tables etc. I am testing error handling and that does not work. If I cause an error in the mysqli_connect line, the DIE never executes. Instead I get the ugly PHP error screen “Fatal error: Uncaught mysqli_sql_exception: …“. How do I output my own custom user-friendly error messages instead?
// var_dump(function_exists('mysqli_connect')); << returns TRUE
$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password);
if (!$db)
{
die('Failed to connect to the server. contact support.'.mysqli_error($db));
}
I tried suppressing the ugly PHP Fatal Error messages in all the ways suggested in other threads (PHP.INI display_errors off, setting error_reporting(0), even using @ in front of the command). All it does is give me a blank screen (no Fatal Errors messages) BUT my custom message does not print out either!!!
This is becoming frustrating because every PHP expert claims my code, written with the DIE, should work. What am I missing? I am running XAMPP CP v3.3 and PHP v8.2.12.
Thanks.