[英]mysql_query return values
The mysql_query
function in php returns TRUE
on success and FALSE
on failure. php中的mysql_query
函数成功返回TRUE
,失败返回FALSE
。
My question is what is considered success ? 我的问题是什么被认为是成功的?
In other words, what is returned when there is nothing from a SELECT
statement, or if there is an UPDATE
and nothing that matches the WHERE
clause. 换句话说,当SELECT
语句没有任何内容,或者UPDATE
没有任何内容与WHERE
子句匹配时,返回的内容。 Does it return FALSE or something like an empty resource ? 它返回FALSE还是类似空的资源?
I'm trying to differentiate between a db error, and an empty result. 我试图区分数据库错误和空结果。
Success means "no errors". 成功意味着“没有错误”。 Getting zero rows is not an error. 获取零行不是错误。
Edit: Just checked the manual page and the explanation is pretty clear (not sure where you got yours): 编辑:刚刚检查了手册页 ,并且说明很清楚(不确定您的位置):
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error . 对于SELECT,SHOW,DESCRIBE,EXPLAIN和其他返回结果集的语句,mysql_query()在成功时返回资源, 在error上返回FALSE 。
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error . 对于其他类型的SQL语句,例如INSERT,UPDATE,DELETE,DROP等,mysql_query()成功返回TRUE ,错误返回FALSE 。
TRUE
means no errors. TRUE
表示没有错误。
If you want to know the number of rows in the resultset
use: mysql_num_rows($result)
. 如果您想知道resultset
集中的行数,请使用: mysql_num_rows($result)
。
If it is an update and you want to know if rows have changed use: mysql_affected_rows($result)
. 如果是更新,并且您想知道行是否已更改,请使用: mysql_affected_rows($result)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.