mysqli::$warning_count
(PHP 5, PHP 7)
mysqli :: $ warning_count - mysqli_warning_count - 返回给定链接上一次查询的警告数
Description
面向对象的风格
int $mysqli->warning_count;
程序风格
int mysqli_warning_count ( mysqli $link )
返回连接中最后一个查询的警告数量。
注意:要检索警告消息,可以使用SQL命令SHOW WARNINGS limit row_count。
Parameters
`link`
仅过程样式:由mysqli_connect()或mysqli_init()返回的链接标识符
Return Values
如果没有警告则警告的数量为零。
Examples
Example #1 $mysqli->warning_count 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();
}
$mysqli->query("CREATE?TABLE?myCity?LIKE?City");
/*?a?remarkable?city?in?Wales?*/
$query?=?"INSERT?INTO?myCity?(CountryCode,?Name)?VALUES('GBR',
????????'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')";
$mysqli->query($query);
if?($mysqli->warning_count)?{
????if?($result?=?$mysqli->query("SHOW?WARNINGS"))?{
????????$row?=?$result->fetch_row();
????????printf("%s?(%d):?%s\n",?$row[0],?$row[1],?$row[2]);
????????$result->close();
????}
}
/*?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();
}
mysqli_query($link,?"CREATE?TABLE?myCity?LIKE?City");
/*?a?remarkable?long?city?name?in?Wales?*/
$query?=?"INSERT?INTO?myCity?(CountryCode,?Name)?VALUES('GBR',
????????'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')";
mysqli_query($link,?$query);
if?(mysqli_warning_count($link))?{
????if?($result?=?mysqli_query($link,?"SHOW?WARNINGS"))?{
????????$row?=?mysqli_fetch_row($result);
????????printf("%s?(%d):?%s\n",?$row[0],?$row[1],?$row[2]);
????????mysqli_free_result($result);
????}
}
/*?close?connection?*/
mysqli_close($link);
?>
上面的例子会输出:
Warning (1264): Data truncated for column 'Name' at row 1
? 1997–2017 The PHP Documentation Group
根据知识共享署名许可证v3.0或更高版本授权。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com