mysql_error
Returns the text error message generated by the previous MySQL operation.
Function name: mysql_error()
Applicable version: PHP 4, PHP 5, PHP 7
Usage: The mysql_error() function is used to return the error message generated by the last MySQL operation.
Syntax: string mysql_error ([ resource $link_identifier = NULL ] )
parameter:
Return value: Returns the error message generated by the most recent MySQL operation, and if no error occurs, an empty string is returned.
Example:
<?php $link = mysql_connect('localhost', 'user', 'password'); if (!$link) { die('连接数据库失败:' . mysql_error()); } $db_selected = mysql_select_db('mydb', $link); if (!$db_selected) { die ('选择数据库失败:' . mysql_error($link)); } // 执行查询操作$result = mysql_query('SELECT * FROM mytable', $link); if (!$result) { die('查询失败:' . mysql_error($link)); } // 关闭连接mysql_close($link); ?>
Notes: