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, it uses the last opened connection. |
Example
In this example, we will try to log into a MySQL server using an incorrect 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