(PHP 4, PHP 5)
mysql_error — 返回上一個 MySQL 操作產生的文本錯誤信息
$link_identifier
= ?): string
返回上一個 MySQL 函數(shù)的錯誤文本,如果沒有出錯則返回
''
(空字符串)。如果沒有指定連接資源號,則使用上一個成功打開的連接從
MySQL 服務器提取錯誤信息。
從 MySQL 數(shù)據(jù)庫后端來的錯誤不再發(fā)出警告,要用 mysql_error() 來提取錯誤文本。注意本函數(shù)僅返回最近一次 MySQL 函數(shù)的執(zhí)行(不包括 mysql_error() 和 mysql_errno())的錯誤文本,因此如果要使用此函數(shù),確保在調用另一個 MySQL 函數(shù)之前檢查它的值。
示例 #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()。