MySQLi Tutorial MySQLi References

mysqli $error_list Property



The mysqli::$error_list / mysqli_error_list() function returns an array of errors for the most recent MySQLi function call that can succeed or fail.

Syntax

//Object-oriented style
$mysqli->error_list;

//Procedural style
mysqli_error_list(mysql)

Parameters

mysql Required. For procedural style only: Specify a mysqli object returned by mysqli_connect() or mysqli_init().

Return Value

Returns a list of errors, each as an associative array containing the errno, error, and sqlstate.

Example: Object-oriented style

The example below shows the usage of mysqli::$error_list property.

<?php
//establishing connection to the database
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_error_list) {
  echo "Failed to connect to MySQL: ". $mysqli->connect_error;
  exit();
}

//executing an SQL query
$sql = "SET x=1";

if (!$mysqli->query($sql)) {
  print_r($mysqli->error_list);
}

//closing the connection
$mysqli->close();
?>

The output of the above code will be similar to:

Array
(
    [0] => Array
        (
            [errno] => 1193
            [sqlstate] => HY000
            [error] => Unknown system variable 'x'
        )

)

Example: Procedural style

The example below shows the usage of mysqli_error_list() function.

<?php
//establishing connection to the database
$mysqli = mysqli_connect("localhost", "user", "password", "database");
if (mysqli_connect_error_list()) {
  echo "Failed to connect to MySQL: ". mysqli_connect_error();
  exit();
}

//executing an SQL query
$sql = "SET x=1";

if (!mysqli_query($mysqli, $sql)) {
  print_r(mysqli_error_list($mysqli));
}

//closing the connection
mysqli_close($mysqli);
?>

The output of the above code will be similar to:

Array
(
    [0] => Array
        (
            [errno] => 1193
            [sqlstate] => HY000
            [error] => Unknown system variable 'x'
        )

)

❮ MySQLi Functions Reference