mysqli_stmt::$errno
(PHP 5, PHP 7)
mysqli_stmt :: $ errno - mysqli_stmt_errno - 返回最近语句调用的错误代码
描述
面向对象的风格
int $mysqli_stmt->errno;
程序风格
int mysqli_stmt_errno ( mysqli_stmt $stmt )
返回可以成功或失败的最近调用的语句函数的错误代码。
客户端错误消息编号列在MySQL errmsg.h头文件中,服务器错误消息编号列在mysqld_error.h中。在MySQL源代码分发中,您可以在Docs / mysqld_error.txt文件中找到错误消息和错误编号的完整列表。
参数
`stmt`
仅过程风格:由mysqli_stmt_init()返回的语句标识符。
返回值
错误代码值。零意味着没有错误发生。
例子
Example #1 Object oriented style
<?php
/*?Open?a?connection?*/
$mysqli?=?new?mysqli("localhost",?"my_user",?"my_password",?"world");
/*?check?connection?*/
if?(mysqli_connect_errno())?{
????printf("Connect?failed:?%s\n",?mysqli_connect_error());
????exit();
}
$mysqli->query("CREATE?TABLE?myCountry?LIKE?Country");
$mysqli->query("INSERT?INTO?myCountry?SELECT?*?FROM?Country");
$query?=?"SELECT?Name,?Code?FROM?myCountry?ORDER?BY?Name";
if?($stmt?=?$mysqli->prepare($query))?{
????/*?drop?table?*/
????$mysqli->query("DROP?TABLE?myCountry");
????/*?execute?query?*/
????$stmt->execute();
????printf("Error:?%d.\n",?$stmt->errno);
????/*?close?statement?*/
????$stmt->close();
}
/*?close?connection?*/
$mysqli->close();
?>
Example #2 Procedural style
<?php
/*?Open?a?connection?*/
$link?=?mysqli_connect("localhost",?"my_user",?"my_password",?"world");
/*?check?connection?*/
if?(mysqli_connect_errno())?{
????printf("Connect?failed:?%s\n",?mysqli_connect_error());
????exit();
}
mysqli_query($link,?"CREATE?TABLE?myCountry?LIKE?Country");
mysqli_query($link,?"INSERT?INTO?myCountry?SELECT?*?FROM?Country");
$query?=?"SELECT?Name,?Code?FROM?myCountry?ORDER?BY?Name";
if?($stmt?=?mysqli_prepare($link,?$query))?{
????/*?drop?table?*/
????mysqli_query($link,?"DROP?TABLE?myCountry");
????/*?execute?query?*/
????mysqli_stmt_execute($stmt);
????printf("Error:?%d.\n",?mysqli_stmt_errno($stmt));
????/*?close?statement?*/
????mysqli_stmt_close($stmt);
}
/*?close?connection?*/
mysqli_close($link);
?>
上面的例子会输出:
Error: 1146.
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com