2

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.

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I read that too, but I thought success could possibly not include an empty result set.
3

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).

1 Comment

WFM. Is there as simple an equivalent in PDO?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.