By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,558 Members | 1,177 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,558 IT Pros & Developers. It's quick & easy.

telling the difference between zero rows returned and failure

P: n/a

Suppose I make a call to MySql and zero rows come back. How do I tell
the difference between zero rows and failure?

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
lk******@geocities.com wrote:
Suppose I make a call to MySql and zero rows come back. How do I tell
the difference between zero rows and failure?


By calling mysql_error() like this:

$result = mysql_query($query) or die(mysql_error());
JW

Jul 17 '05 #2

P: n/a
lk******@geocities.com wrote:
Suppose I make a call to MySql and zero rows come back. How do I tell
the difference between zero rows and failure?


0==false evals to true ("loose" comparison), but 0===false evals to false
(stricter comparation where types also matter), see
http://www.php.net/manual/en/types.comparisons.php for a more complete
overview and
http://www.php.net/manual/en/languag...comparison.php for the
available comparison operators.

Jul 17 '05 #3

P: n/a
lk******@geocities.com wrote:
Suppose I make a call to MySql and zero rows come back. How do I tell
the difference between zero rows and failure?


From the mysql_query() doc:

Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query()
returns a resource identifier or FALSE if the query was not executed
correctly. For other type of SQL statements, mysql_query() returns TRUE
on success and FALSE on error. A non-FALSE return value means that the
query was legal and could be executed by the server. It does not
indicate anything about the number of rows affected or returned.
From the mysql_num_rows() doc:

mysql_num_rows() returns the number of rows in a result set. This
command is only valid for SELECT statements.
In other words: if mysql_query() returns false, it's failure. If it's
not failure, then you can use mysql_num_rows() to see how many rows you get.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.