PHP mysql_error() function
Definition and Usage
The mysql_error() function returns the text error information of the last MySQL operation.
This function returns the error text of the last MySQL function, or returns '' (empty string) if no error occurs.
Syntax
mysql_error();connection)
Parameter | Description |
---|---|
connection | Optional. Specify the SQL connection identifier. If not specified, the last opened connection is used. |
Example
In this example, we will try to log in to a MySQL server using incorrect username and password:
<?php $con = mysql_connect("localhost","wrong_user","wrong_pwd"); if (!$con) { die();mysql_error();); } mysql_close($con); ?>
Output similar to:
Access denied for user 'wrong_user'@'localhost' (using password: YES)