Name

mysql_errno( )

Synopsis

mysql_errno([connection])

This returns the error code number for the last MySQL statement issued. The function returns 0 if there was no error. Another MySQL connection identifier may be given as an argument for the function.

...
$sql_stmnt = "SELECT * FROM workreqs";
$results = mysql_db_query('workrequests', $sql_stmnt)
           or die (mysql_errno( ) . " " . mysql_error( ) . "\n");
$count = mysql_num_rows($results);
print "Number of Rows Found:  $count \n";
...

I’ve intentionally typed the name of the table incorrectly in the preceding SQL statement. It should read workreq and not workreqs. The result of this script follows:

1146 Table 'workrequests.workreqs' doesn't exist

Notice that the error number code is given by mysql_errno( ) and the message that follows it is given by mysql_error( ), which provides an error message rather than a code.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.