PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<mysql_errnomysql_escape_string>
Last updated: Mon, 16 Jul 2012

mysql_error

(PHP 3, PHP 4, PHP 5)

mysql_error --  返回上一个 MySQL 操作产生的文本错误信息

说明

string mysql_error ( [resource link_identifier] )

返回上一个 MySQL 函数的错误文本,如果没有出错则返回 ''(空字符串)。如果没有指定连接资源号,则使用上一个成功打开的连接从 MySQL 服务器提取错误信息。

从 MySQL 数据库后端来的错误不再发出警告,要用 mysql_error() 来提取错误文本。注意本函数仅返回最近一次 MySQL 函数的执行(不包括 mysql_error()mysql_errno())的错误文本,因此如果要使用此函数,确保在调用另一个 MySQL 函数之前检查它的值。

例子 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()




<mysql_errnomysql_escape_string>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST