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

mysqli_stmt::$error

(mysqli_stmt_error) Returns the string description of the error in the previous statement
Name:mysqli_stmt::$error
Category:MySQLi
Programming Language:php
One-line Description:Get the error message generated by the last executed preprocessing statement

mysqli_stmt::$error() is a method of PHP's mysqli_stmt class, which is used to obtain the error information generated by the preprocessing statement that was executed the last time.

usage:

 string mysqli_stmt::$error ( void )

Parameter Description: This method has no parameters.

Return value: Returns a string indicating the error message generated by the last executed preprocessing statement.

Example:

 // 创建数据库连接$mysqli = new mysqli("localhost", "username", "password", "database"); // 准备预处理语句$stmt = $mysqli->prepare("SELECT * FROM users WHERE username = ?"); // 绑定参数$username = "john"; $stmt->bind_param("s", $username); // 执行预处理语句$stmt->execute(); // 获取错误信息$error = $stmt->error(); // 输出错误信息if ($error) { echo "错误信息:" . $error; } else { echo "预处理语句执行成功!"; } // 关闭预处理语句和数据库连接$stmt->close(); $mysqli->close();

In the example above, we first create a mysqli object and connect to the database. We then prepare a preprocessing statement for selecting a user with a specific username from the database. We bind a parameter and execute the preprocessing statement. Then, we use the $stmt->error() method to get the error information generated by the last executed preprocessing statement and store it in the variable $error . Finally, we output the corresponding message based on whether there is an error message.

Note that mysqli_stmt::$error() method can only be used with mysqli_stmt objects, not mysqli objects.

Similar Functions
Popular Articles