PHP mysqli_error_list() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_error_list() returns a list of errors from the last MySQLi function call as an array of associative arrays.

Object-oriented style reads the $mysqli->error_list property. Each item typically includes errno, sqlstate and error. Most simple queries produce either an empty list or one entry; some operations can return more.

Syntax

Call mysqli_error_list() with the values you need. Start with this line.

PHP
$list = mysqli_error_list($mysqli);
CallWhat it does
mysqli_error_list($mysqli)Returns an array of error entries for the connection.
$mysqli->error_listObject-oriented property form.
count(mysqli_error_list($mysqli))Counts how many error entries were reported.

When there is no error, the list is empty. For a quick single message, mysqli_error() is enough. Use error_list when you want structured errno/sqlstate/error fields together.

Library declarations
PHP
mysqli_error_list(mysqli $mysql): array

Parameters

ParameterDescription
mysqlRequired. The mysqli connection to inspect.

Return Value

Return ValueDescription
arrayA list of associative arrays with keys such as errno, sqlstate and error.

PHP Examples

Example 1 — Empty List After Success

Show that a good query leaves error_list empty.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
mysqli_query($mysqli, "SELECT 1");
var_export(mysqli_error_list($mysqli));
echo PHP_EOL;
mysqli_close($mysqli);

How It Works

  1. SELECT 1 succeeds.
  2. error_list has no entries.
  3. var_export prints an empty array.
  4. Sample output when connected to a demo database.

Example 2 — Inspect One Error Entry

Print errno, sqlstate and error from the list.

PHP
<?php
$mysqli = new mysqli("localhost", "demo", "secret", "shop");
$mysqli->query("SELECT * FROM no_such_table");

foreach ($mysqli->error_list as $item) {
    echo $item["errno"], " ", $item["sqlstate"], " ", $item["error"], PHP_EOL;
}

$mysqli->close();

How It Works

  1. A missing table produces a server error.
  2. error_list contains one associative array.
  3. The loop prints the structured fields.
  4. Sample output shows errno, sqlstate and message.

Example 3 — Procedural error_list Helper

Use the function form and count the entries.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
mysqli_query($mysqli, "SELECT * FROM no_such_table");
$list = mysqli_error_list($mysqli);
echo "errors=", count($list), PHP_EOL;
if ($list) {
    echo $list[0]["error"], PHP_EOL;
}
mysqli_close($mysqli);

How It Works

  1. The bad query fills error_list.
  2. count() reports one entry.
  3. The first item's error text is printed.
  4. This is useful in shared logging helpers.

Frequently Asked Questions

An array of error records for the last MySQLi operation. Each record usually has errno, sqlstate and error keys.
Read $mysqli->error_list. It is the same structured list as the procedural function.
When the last operation succeeded and left no error information.
error() is one string. error_list() gives structured fields and can hold multiple entries for some operations.
No. You can enable mysqli exceptions and still inspect error_list when you catch a failure or when exceptions are disabled.

Next: mysqli_escape_string()

mysqli_escape_string() escapes special characters in a string for use in a SQL statement o.

mysqli_escape_string() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful