mysql_error function, return error message

 The PHP mysql_error() function is used to return the error message generated by the previous MySQL operation. The output result is only if there is an error message. If there is no error, only the null value (empty string) will be inverted. Normally doing MySQL operation It is very easy to use when debugging.


PHP mysql_error() function syntax

string mysql_error (mysql execution information)


The "mysql execution information" in the parentheses is a non-essential item. If you do not fill in this part, you can just write mysql_error(). This will return the error message of the operation performed by MySQL. A simple example will be given for your reference.

PHP mysql_error() function example
<?php
$connect = mysql_connect("localhost","UserName","Password");
if (!$connect) {
 echo mysql_error();
}
?>
In the example, we first wrote a simple MySQL database connection syntax, using the mysql_connect function, where UserName and Password are the account and password of the database connection. If you fill in the wrong data, the following if judgment will be An error message will be output, similar to the one below.

Warning : mysql_connect() [function.mysql-connect]: Access denied for user'UserName'@'localhost' (using password: YES) in...

Post a Comment

0 Comments