PHP mysqli_error() Function
In this chapter you will learn:
- Definition for PHP mysqli_error() Function
- Syntax for PHP mysqli_error() Function
- Parameter for PHP mysqli_error() Function
- Return for PHP mysqli_error() Function
- Example - Get the last error for the most recent function call
Definition
The mysqli_error() function returns the last error for the most recent function call.
Syntax
PHP mysqli_error() Function has the following syntax.
mysqli_error(connection);
Parameter
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
Return
A string that describes the error. An empty string if no error occurred.
Example
Get the last error for the most recent function call
<?php//from ja va 2 s . com
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform a query, check for error
if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES ('Jack')")){
echo("Error description: " . mysqli_error($con));
}
mysqli_close($con);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_error_list() Function
- Syntax for PHP mysqli_error_list() Function
- Parameter for PHP mysqli_error_list() Function
- Return for PHP mysqli_error_list() Function
- Example - returns a list of errors for the most recent function call
Home » PHP Tutorial » PHP MySQLi Functions