mysql_error
(PHP 4, PHP 5)
mysql_error — 返回上一個 MySQL 操作產生的文字錯誤資訊
說明
mysql_error(resource
$link_identifier
= ?): string
返回上一個 MySQL 函式的錯誤文字,如果沒有出錯則返回
''
(空字串)。如果沒有指定連線資源號,則使用上一個成功打開的連線從
MySQL 伺服器提取錯誤資訊。
從 MySQL 數據庫後端來的錯誤不再發出警告,要用 mysql_error() 來提取錯誤文字。注意本函式僅返回最近一次 MySQL 函式的執行(不包括 mysql_error() 和 mysql_errno())的錯誤文字,因此如果要使用此函式,確保在呼叫另一個 MySQL 函式之前檢查它的值。
示例 #1 mysql_error 例子
<?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_errno()。