PHP mysqli: error_list() Function
mysqli_error_list() function / mysqli::$error_list
The mysqli_error_list() function / mysqli::$error_list returns a list of errors for the most recent function call, if any.
Syntax:
Object oriented style
array $mysqli->error_list;
Procedural style
array mysqli_error_list ( mysqli $link )
Parameter:
Name | Description | Required/Optional |
---|---|---|
link | A link identifier returned by mysqli_connect() or mysqli_init() | Required for procedural style only and Optional for Object oriented style |
Usage: Procedural style
mysqli_error_list(connection);
Parameter:
Name | Description | Required/Optional |
---|---|---|
connection | Specifies the MySQL connection to use. | Required |
Return value:
A list of errors, each as an associative array containing the errno, error, and sqlstate.
Version:PHP 5 >= 5.4.0, PHP 7
Example of object oriented style:
<?php
$mysqli = new mysqli("localhost", "user1", "datasoft123", "hr");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (!$mysqli->query("SET a=1")) {
print_r($mysqli->error_list);
}
/* close connection */
$mysqli->close();
?>
Example of procedural style:
<?php
$link = mysqli_connect("localhost", "user1", "datasoft123", "hr");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (!mysqli_query($link, "SET a=1")) {
print_r(mysqli_error_list($link));
}
/* close connection */
mysqli_close($link);
?>
Output:
Array ( [0] => Array ( [errno] => 1193 [sqlstate] => HY000 [error] => Unknown system variable 'a' ) )
Example:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform a query, check for error
if (!mysqli_query($con,"INSERT INTO employees (First_Name) VALUES ('David')"))
{
print_r(mysqli_error_list($con));
}
mysqli_close($con);
?>
Sample Output:
Parse error: parse error in C:\wamp\www\php\function-reference\mysqli.php on line 10
See also
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/php/function-reference/mysqli_error_list.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics