导航首页 » 技术教程 » PHP:MySQL函数mysql_errno()的用法
PHP:MySQL函数mysql_errno()的用法 145 2023-12-13   

mysql_errno

(PHP 4, PHP 5)

mysql_errno — 返回上一个 MySQL 操作中的错误信息的数字编码

说明

int mysql_errno ([ resource $link_identifier ] )

返回上一个 MySQL 函数的错误号码,如果没有出错则返回 0(零)。

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

Example #1 mysql_errno() 例子

<?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

Note:

如果指定了可选参数则用给定的连接提取错误代码。否则使用上一个打开的连接。

参见 mysql_error()。


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103