Using the typical MySQL connection method, if the connection fails (ex. bad credentials), I'd like the user to be notified with a nice redirect with error message, instead of a plain text Fatal Error message with technical jargon.
$db = new MySQLi($hostname, $username, $password, $database);
if ($db->connect_error) {
echo "Error: ".$db->connect_error;
die();
}
Shows a plain text page with an error message, if I have error_reporting
on. What I'd like to do is something like:
if ($db->connect_error) {
// Failed
header('location: ../setup_db.php?connect_error=1');
die();
} else {
// Connected. Do stuff...
}
Unfortunately, I cannot get PHP to get past the failed connection error that quits the program. Is there a way to get a signal from MySQL or PHP that the connection won't work but continue to run the program?
For further info, the error printed currently is not a printout of $db->error_connect
, but a PHP error:
Fatal error: Uncaught mysqli_sql_exception: php_network_getaddresses: getaddrinfo for...