mysqli::$errno
(PHP 5, PHP 7)
mysqli :: $ errno - mysqli_errno - 返回最近函数调用的错误代码
Description
面向对象的风格
int $mysqli->errno;
程序风格
int mysqli_errno ( mysqli $link )
返回成功或失败的最近MySQLi函数调用的最后一个错误代码。
客户端错误消息编号列在MySQL errmsg.h头文件中,服务器错误消息编号列在mysqld_error.h中。在MySQL源代码分发中,您可以在Docs / mysqld_error.txt文件中找到错误消息和错误编号的完整列表。
Parameters
`link`
仅过程样式:由mysqli_connect()或mysqli_init()返回的链接标识符
Return Values
上次调用的错误代码值,如果失败。零意味着没有错误发生。
Examples
Example #1 $mysqli->errno example
面向对象的风格
<?php
$mysqli?=?new?mysqli("localhost",?"my_user",?"my_password",?"world");
/*?check?connection?*/
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);
}
/*?close?connection?*/
$mysqli->close();
?>
程序风格
<?php
$link?=?mysqli_connect("localhost",?"my_user",?"my_password",?"world");
/*?check?connection?*/
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));
}
/*?close?connection?*/
mysqli_close($link);
?>
上面的例子会输出:
Errorcode: 1193
? 1997–2017 The PHP Documentation Group
根据知识共享署名许可证v3.0或更高版本授权。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com