PHP mysqli error_list() 函数
示例 - 面向对象的样式
返回最近调用函数的最后一个错误代码:
<?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();
?>
$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();
?>
查看底部的程序样式示例。
定义和用法
error_list / mysqli_error_list() 函数返回最近调用函数的错误列表。
语法
面向对象的风格:
$mysqli -> error_list
程序风格:
mysqli_error_list(connection)
参数值
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
技术细节
返回值: | 返回错误列表。每个错误都是一个带有 errno(错误代码)、error(错误文本)和 sqlstate 的关联数组。 |
---|---|
PHP 版本: | 5.4+ |
示例 - 程序样式
返回最近调用函数的最后一个错误代码:
<?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);
?>
$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);
?>