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)
mysqli::errno -- mysqli_errno — 返回最近函数调用的错误代码
面向对象风格
过程化风格
返回最近的mysqli函数调用产生的错误代码.
客户端错误在Mysqlerrmsg.h头文件中列出, 服务端错误好在mysqld_error.h中列出. 在mysql源码分发包中的Docs/mysqld_error.txt你可以发现一个完整的错误消息和错误号.
最后一次调用产生的错误代码, 返回0代表没有错误发生.
Example #1 mysqli->errno example
面向对象风格
<?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