Current Location: Home> Function Categories> mysqli_stmt::$error_list

mysqli_stmt::$error_list

(mysqli_stmt_error_list) Returns the error list of the previous execution statement
Name:mysqli_stmt::$error_list
Category:MySQLi
Programming Language:php
One-line Description:Get the error list of the most recent execution preprocessing statement

Function name: mysqli_stmt::$error_list()

Applicable version: PHP 5 >= 5.4.0, PHP 7

Function description: The mysqli_stmt::$error_list() method is used to get the error list of the most recently executed preprocessing statement.

usage:

 mysqli_stmt::$error_list(): array

Parameter Description: This function does not accept any parameters.

Return value: Return an array containing error messages, each error message is represented as an associative array, containing the following keys:

  • "errno": indicates an error code.
  • "sqlstate": Indicates SQLSTATE error code.
  • "error": indicates an error message.

Example:

 $conn = new mysqli("localhost", "username", "password", "database"); $stmt = $conn->stmt_init(); $stmt->prepare("SELECT * FROM users WHERE id = ?"); $stmt->bind_param("i", $id); // 执行预处理语句$stmt->execute(); // 获取错误列表$errorList = $stmt->error_list; if (count($errorList) > 0) { foreach ($errorList as $error) { echo "错误代码: " . $error['errno'] . "<br>"; echo "SQLSTATE 错误代码: " . $error['sqlstate'] . "<br>"; echo "错误消息: " . $error['error'] . "<br>"; } } else { echo "预处理语句执行成功!"; } $stmt->close(); $conn->close();

In the example above, a mysqli connection object is first created and a mysqli_stmt object is initialized. Then use the prepare() method to prepare a SQL query statement with parameter placeholders. Next, use the bind_param() method to bind the parameters. Then, the preprocessing statement is executed by executing the execute() method.

Finally, get the error list by accessing the error_list property. If the error list is not empty, iterate over the error list and print the error code, SQLSTATE error code, and error message for each error. If the error list is empty, it means that the preprocessing statement is executed successfully.

Please note that for demonstration, the database connection parameters ("localhost", "username", "password", "database") in the above example need to be replaced according to actual conditions.

Similar Functions
Popular Articles