HNY!!
I cannot get $mysqli->error or $mysqli->errno to react to a forced error.
<?php
// Connect to the db
$mysqli = new mysqli("localhost", "user", "BADpassWord", "db") // this does create the error
// Check connection
if ($mysqli->errno) // no response from this
{
printf( "The error message is: %s", $mysqli->error); // no response from this
}
?>
PHP does catch the error, but I cannot get MySQL to let me intercede.
I have also tried:
<?php
$mysqli = new mysqli("localhost", "user", "BADpassWord", "db")
or die("Connection failed");
echo "I made it this far";
?>
and "I made it this far" gets printed out to the browser, along with the PHP error message. But it totally ignores the die().
Any help would be appreciated.
Thanks
Noob question re: why I can't get error message or number
Moderator: General Moderators
Re: Noob question re: why I can't get error message or number
try:
but most of the time we dont do:
Code: Select all
// Returns a MySQL link identifier on success, or FALSE on failure.
mysql_connect("localhost", "username", "bad password") or die(mysql_error());
Code: Select all
$someVariable = mysql_connect("localhost", "username", "bad password") or die(mysql_error());
Re: Noob question re: why I can't get error message or number
Sorry person with a seemingly random username, I have to disagree with that. Apart from OP trying to use mysqli and not mysql, the "most of the time we don't do" isn't accurate.
bartolo:
1. If there's an error connecting you need to use ::connect_errno and ::connect_error instead.
2. new will always return an object, and an object is never treated as false. The "or die" will never happen.
bartolo:
1. If there's an error connecting you need to use ::connect_errno and ::connect_error instead.
2. new will always return an object, and an object is never treated as false. The "or die" will never happen.