You can also find the error codes for for example MySQL 5.5 here: http://dev.mysql.com/doc/refman/5.5/en/error-handling.html
(PHP 5, PHP 7, PHP 8)
mysqli::$errno -- mysqli_errno — 返回最近函数调用的错误代码
面向对象风格
过程化风格
返回最近一次 mysqli 函数调用成功或者失败产生的错误代码。
上次调用产生的错误代码(如果失败), 0 代表没有错误发生。
示例 #1 $mysqli->errno 示例
面向对象风格
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* 检查连接 */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if (!$mysqli->query("SET a=1")) {
printf("Errorcode: %d\n", $mysqli->errno);
}
/* 关闭连接 */
$mysqli->close();
?>
过程化风格
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* 检查连接 */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (!mysqli_query($link, "SET a=1")) {
printf("Errorcode: %d\n", mysqli_errno($link));
}
/* 关闭连接 */
mysqli_close($link);
?>
以上示例会输出:
Errorcode: 1193
You can also find the error codes for for example MySQL 5.5 here: http://dev.mysql.com/doc/refman/5.5/en/error-handling.html