mysqli::errno

mysqli_errno

(PHP 5, PHP 7, PHP 8)

mysqli::errno -- mysqli_errno返回最近函數(shù)調(diào)用的錯誤代碼

說明

面向?qū)ο箫L(fēng)格

int $errno;

過程化風(fēng)格

mysqli_errno(mysqli $link): int

返回最近的mysqli函數(shù)調(diào)用產(chǎn)生的錯誤代碼.

客戶端錯誤在Mysqlerrmsg.h頭文件中列出, 服務(wù)端錯誤好在mysqld_error.h中列出. 在mysql源碼分發(fā)包中的Docs/mysqld_error.txt你可以發(fā)現(xiàn)一個完整的錯誤消息和錯誤號.

參數(shù)

mysql

僅以過程化樣式:由mysqli_connect()mysqli_init() 返回的 mysqli 對象。

返回值

最后一次調(diào)用產(chǎn)生的錯誤代碼, 返回0代表沒有錯誤發(fā)生.

范例

示例 #1 mysqli->errno example

面向?qū)ο箫L(fēng)格

<?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);
}

/* 關(guān)閉連接 */
$mysqli->close();
?>

過程化風(fēng)格

<?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));
}

/* 關(guān)閉連接 */
mysqli_close($link);
?>

以上例程會輸出:

Errorcode: 1193

參見