PHP mysql_error() 函數(shù)
定義和用法
mysql_error() 函數(shù)返回上一個(gè) MySQL 操作產(chǎn)生的文本錯(cuò)誤信息。
本函數(shù)返回上一個(gè) MySQL 函數(shù)的錯(cuò)誤文本,如果沒有出錯(cuò)則返回 ''(空字符串)。
語法
mysql_error(connection)
參數(shù) | 描述 |
---|---|
connection | 可選。規(guī)定 SQL 連接標(biāo)識(shí)符。如果未規(guī)定,則使用上一個(gè)打開的連接。 |
例子
在本例中,我們將嘗試使用錯(cuò)誤的用戶名和密碼來登錄一個(gè) MySQL 服務(wù)器:
<?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)