PHP mysql_errno() Function

Definition and Usage

The mysql_errno() function returns the numeric code of the error information in the last MySQL operation.

Returns the error number of the last MySQL function, or 0 (zero) if no error occurred.

Syntax

mysql_errno(connection)
Parameter Description
connection Optional. Specifies the SQL connection identifier. If not specified, the last opened connection is used.

Example

In this example, we will try to log into a MySQL server using a wrong username and password:

<?php
$con = mysql_connect("localhost","wrong_user","wrong_pwd");
if (!$con)
  {
  die('Could not connect: ' . mysql_errno());
  }
mysql_close($con);
?>

Output similar to:

Could not connect: 1045