mysql_errno

(PHP 4, PHP 5)

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

說明

mysql_errno(resource $link_identifier = ?): int

返回上一個 MySQL 函數(shù)的錯誤號碼,如果沒有出錯則返回 0(零)。

從 MySQL 數(shù)據(jù)庫后端來的錯誤不再發(fā)出警告,要用 mysql_errno() 來提取錯誤代碼。注意本函數(shù)僅返回最近一次 MySQL 函數(shù)的執(zhí)行(不包括 mysql_error()mysql_errno())的錯誤代碼,因此如果要使用此函數(shù),確保在調用另一個 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ù)則用給定的連接提取錯誤代碼。否則使用上一個打開的連接。

參見 mysql_error()