mysqli::get_warnings
(mysqli_get_warnings) Obtain the results of SHOW WARNINGS
Function name: mysqli::get_warnings()
Applicable version: PHP 5.3.0 and above
Function description: The mysqli::get_warnings() method is used to obtain warnings or error messages related to the most recent execution statement. This method can only be called after the last query of the mysqli object connection to get warning information.
Syntax: mysqli::get_warnings()
Return value: Returns an instance of the mysqli_warning object, indicating the warning information in the query.
Sample code:
// 创建mysqli对象并连接到数据库$mysqli = new mysqli("localhost", "username", "password", "database"); // 执行查询语句$result = $mysqli->query("SELECT * FROM table"); // 获取警告信息$warnings = $mysqli->get_warnings(); // 遍历并打印警告信息while ($warning = $warnings->fetch_object()) { echo "警告:".$warning->message."\n"; echo "错误码:".$warning->errno."\n"; echo "SQL状态:".$warning->sqlstate."\n"; } // 关闭数据库连接$mysqli->close();
Notes: