PHP mysqli error_list() Function

❮ PHP MySQLi Reference

Example - Object Oriented style

Return a list of errors from the last executed command, if any:

<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");

if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}

// Perform a query, check for error
if (!$mysqli -> query("INSERT INTO Persons (FirstName) VALUES ('Glenn')")) {
  print_r($mysqli -> error_list);
}

$mysqli -> close();
?>

Look at example of procedural style at the bottom.


Definition and Usage

The error_list / mysqli_error_list() function returns a list of errors from the last executed command, if any.


Syntax

Object oriented style:

$mysqli -> error_list

Procedural style:

mysqli_error_list(connection)

Parameter Values

Parameter Description
connection Required. Specifies the MySQL connection to use

Technical Details

Return Value: Returns a list of errors as an associative array; with errno (error code), error (error text), and sqlstate
PHP Version: 5.4+

Example - Procedural style

Return a list of errors from the last executed command, if any:

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");

if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  exit();
}

// Perform a query, check for error
if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES ('Glenn')")) {
  print_r(mysqli_error_list($con));
}

mysqli_close($con);
?>


❮ PHP MySQLi Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.