mysql_errno
(PHP 4, PHP 5)
mysql_errno — 返回上一個 MySQL 操作中的錯誤資訊的數字編碼
說明
mysql_errno(resource
$link_identifier
= ?): int
返回上一個 MySQL 函式的錯誤號碼,如果沒有出錯則返回
0
(零)。
從 MySQL 數據庫後端來的錯誤不再發出警告,要用 mysql_errno() 來提取錯誤程式碼。注意本函式僅返回最近一次 MySQL 函式的執行(不包括 mysql_error() 和 mysql_errno())的錯誤程式碼,因此如果要使用此函式,確保在呼叫另一個 MySQL 函式之前檢查它的值。
示例 #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";
?>
以上例子將產生如下輸出:
1049: Unknown database 'nonexistentdb' 1146: Table 'kossu.nonexistenttable' doesn't exist
注意:
如果指定了可選參數則用給定的連線提取錯誤程式碼。否則使用上一個打開的連線。
參見 mysql_error()。