MySQL query on error returns an error number for reference. This error number can be collected or can be further processed as per requirement. Even we can post the error number along with error message to an email address. Getting the error number is simple. We have to use mysql_errno() function. Please note that this command will return the error number associated with most recent MySQL query. It will return zero if no error is associated.
So we have to check this before going to next mysql query. Printing error message along with error number is a good idea.
$querry = mysql_query("SELECT new_field FROM student");
echo "Error Number= ".mysql_errno(); // will print 1054
In the above table student new_field is a non existence field or column.
$pdo=$dbo->prepare('Select * from nonexistence_table');
if($pdo->execute()){
echo 'Success<br>';
}else{
print_r($pdo->errorCode());
}
The output of above code is here
42S02
This is the error number returned by PDO.
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.
| Purandam Mohanta | 25-06-2009 |
| Pls send me error list of mysql. This topic is very usefull to me. Thanking you. | |