The mysql_query
function in php returns TRUE
on success and FALSE
on failure.
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. Does it return FALSE or something like an empty resource ?
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 .
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error .
TRUE
means no errors.
If you want to know the number of rows in the resultset
use: mysql_num_rows($result)
.
If it is an update and you want to know if rows have changed use: mysql_affected_rows($result)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.