PHP mysql_error() 函數(shù)
定義和用法
mysql_error() 函數(shù)返回上一個 MySQL 操作產生的文本錯誤信息。
本函數(shù)返回上一個 MySQL 函數(shù)的錯誤文本,如果沒有出錯則返回 ''(空字符串)。
語法
mysql_error(connection)
| 參數(shù) | 描述 |
|---|---|
| connection | 可選。規(guī)定 SQL 連接標識符。如果未規(guī)定,則使用上一個打開的連接。 |
例子
在本例中,我們將嘗試使用錯誤的用戶名和密碼來登錄一個 MySQL 服務器:
<?php
$con = mysql_connect("localhost","wrong_user","wrong_pwd");
if (!$con)
{
die(mysql_error());
}
mysql_close($con);
?>
輸出類似:
Access denied for user 'wrong_user'@'localhost' (using password: YES)