array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.mysql-error.php', 1 => 'mysql_error', ), 'up' => array ( 0 => 'ref.mysql.php', 1 => 'MySQL 函数', ), 'prev' => array ( 0 => 'function.mysql-errno.php', 1 => 'mysql_errno', ), 'next' => array ( 0 => 'function.mysql-escape-string.php', 1 => 'mysql_escape_string', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/mysql/functions/mysql-error.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5)
mysql_error — 返回上一个 MySQL 操作中的错误信息的文本
本扩展自 PHP 5.5.0 起已废弃,并在自 PHP 7.0.0 开始被移除。应使用 MySQLi 或 PDO_MySQL 扩展来替换之。参见 MySQL:选择 API 指南来获取更多信息。用以替代本函数的有:
返回上一个 MySQL 函数的错误文本。 从 MySQL 数据库后端来的错误不再发出警告。要用 mysql_error() 来检索错误文本。注意本函数仅返回最近执行的 MySQL 函数(不包括 mysql_error() 和 mysql_errno())的错误文本,因此如果要使用此函数,确保在调用另一个 MySQL 函数之前检查它的值。
link_identifier
MySQL
连接。如不指定连接标识,则使用由 mysql_connect()
最近打开的连接。如果没有找到该连接,会尝试不带参数调用
mysql_connect()
来创建。如没有找到连接或无法建立连接,则会生成
E_WARNING
级别的错误。
返回上一个 MySQL 函数的错误文本,如果没有出错则返回
''
(空字符串)。
示例 #1 mysql_error() 示例
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";
mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
以上示例的输出类似于:
1049: Unknown database 'nonexistentdb' 1146: Table 'kossu.nonexistenttable' doesn't exist