PHP Function Reference

PHP mysqli_stmt $error_list Property



The PHP mysqli_stmt::$error_list / mysqli_stmt_error_list() function returns an array of errors for the most recent statement call that can succeed or fail.

Syntax

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

//Procedural style
mysqli_stmt_error_list(statement)

Parameters

statement Required. For procedural style only: Specify a mysqli_stmt object returned by mysqli_stmt_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_stmt::$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();
}

$sql = "SELECT Name, Age FROM Employee ORDER BY Age";
if ($stmt = $mysqli->prepare($sql)) {

  //dropping the table
  $mysqli->query("DROP TABLE Employee");

  //executing the query
  $stmt->execute();

  print_r($stmt->error_list);

  //closing the statement
  $stmt->close();
}

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

The output of the above code will be similar to:

Array
(
    [0] => Array
        (
            [errno] => 1146
            [sqlstate] => 42S02
            [error] => Table 'database.Employee' doesn't exist
        )

)

Example: Procedural style

The example below shows the usage of mysqli_stmt_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();
}

$sql = "SELECT Name, Age FROM Employee ORDER BY Age";
if ($stmt = mysqli_prepare($mysqli, $sql)) {

  //dropping the table
  mysqli_query($mysqli, "DROP TABLE Employee");

  //executing the query
  mysqli_stmt_execute($stmt);

  print_r((mysql_stmt_error_list($stmt));

  //closing the statement
  mysqli_stmt_close($stmt);
}

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

The output of the above code will be similar to:

Array
(
    [0] => Array
        (
            [errno] => 1146
            [sqlstate] => 42S02
            [error] => Table 'database.Employee' doesn't exist
        )

)

❮ PHP MySQLi Reference