cuốn sách gpt4 ai đã làm

PHP 和 MySQL,当查询没有产生任何行时返回什么?

In lại Tác giả: Hồ Xil 更新时间:2023-11-01 07:21:02 25 4
mua khóa gpt4 Nike

我对 MySQL 的 PHP 接口(interface)有些困惑。 mysql_query(用于执行命令和查询)的文档说明了返回值:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.

我知道我可以调用 mysql_num_rows 来计算查询返回的行数,假设我在 {SELECT, SHOW, DESCRIBE, EXPLAIN} 集中执行了命令。

除此之外……如果该集合中的查询成功执行(在数据库方面)但未返回任何结果行,会发生什么情况?在那种情况下 mysql_query 返回 true 还是 false(即这是失败条件)?使用此界面检查成功查询的“无结果”可能性的最佳方法是什么?

câu trả lời hay nhất

这属于文档第一部分的情况:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

不返回结果行的查询既不会返回ĐÚNG VẬY,也不会返回SAI,而是返回一个资源对象。

但是,资源对象将没有行,即 mysql_num_rows() sẽ trở lại 0 并且第一次调用 mysql_fetch_* sẽ trở lại FALSE。有多种方法可以检测到这种情况,但调用 mysql_num_rows() 可能是最简单的方法之一。

关于PHP 和 MySQL,当查询没有产生任何行时返回什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7716906/

25 4 0
Bài viết khuyến nghị: PHP 和 SQL Server - 思考
Bài viết khuyến nghị: ios - Swift 解析 JSON 格式
Bài viết khuyến nghị: ios - Swift - 从导航系统中删除 View Controller
Bài viết khuyến nghị: PHP/mysql - 我的时间戳不喜欢在大于 (>) 语句中
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress