mysqli_errno()
实例
返回最近调用函数的最后一个错误代码:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform a query, check for error
if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES (‘Glenn‘)"))
{
echo("Errorcode: " . mysqli_errno($con));
}
mysqli_close($con);
?>
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform a query, check for error
if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES (‘Glenn‘)"))
{
echo("Errorcode: " . mysqli_errno($con));
}
mysqli_close($con);
?>
定义和用法
mysqli_errno() 函数返回最近调用函数的最后一个错误代码。
语法
mysqli_errno(connection);
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
技术细节
返回值: | 返回错误代码值。如果没有错误发生则返回 0。 |
---|---|
PHP 版本: | 5+ |