SQL PHP HTML ASP JavaScript articles and free scripts to download
SQL PHP MySQL Functions

Error number displaying after execution of a query

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. Here is an example of this error number. Let us see what error we will get in case of generated error out of one non existence field name called in an mysql select query.

$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.

Error Number for PHP PDO

We will be using PDO for connecting and using MySQL database from PHP. PDO has errorCode() function to display error numbers.
Here is the code to display error number

$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.

We will get a meaningful interpretation if we can mix this error number with error message. Next we will study that..

Number of User Comments : 1


Google+

More on PHP MySQL functions
Purandam Mohanta25-06-2009
Pls send me error list of mysql. This topic is very usefull to me.
Thanking you.
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer