mysql_errno

(PHP 4, PHP 5)

mysql_errno 返回上一個(gè) MySQL 操作中的錯(cuò)誤信息的數(shù)字編碼

說(shuō)明

mysql_errno(resource $link_identifier = ?): int

返回上一個(gè) MySQL 函數(shù)的錯(cuò)誤號(hào)碼,如果沒(méi)有出錯(cuò)則返回 0(零)。

從 MySQL 數(shù)據(jù)庫(kù)后端來(lái)的錯(cuò)誤不再發(fā)出警告,要用 mysql_errno() 來(lái)提取錯(cuò)誤代碼。注意本函數(shù)僅返回最近一次 MySQL 函數(shù)的執(zhí)行(不包括 mysql_error()mysql_errno())的錯(cuò)誤代碼,因此如果要使用此函數(shù),確保在調(diào)用另一個(gè) MySQL 函數(shù)之前檢查它的值。

示例 #1 mysql_errno() 例子

<?php
    mysql_connect
("localhost""mysql_user""mysql_password");

    
mysql_select_db("nonexistentdb");
    echo 
mysql_errno() . ": " mysql_error(). "\n";

    
mysql_select_db("kossu");
    
mysql_query("SELECT * FROM nonexistenttable");
    echo 
mysql_errno() . ": " mysql_error() . "\n";
?>

以上例子將產(chǎn)生如下輸出:

1049: Unknown database 'nonexistentdb'
1146: Table 'kossu.nonexistenttable' doesn't exist

注意:

如果指定了可選參數(shù)則用給定的連接提取錯(cuò)誤代碼。否則使用上一個(gè)打開(kāi)的連接。

參見(jiàn) mysql_error()