Connecting Tech Pros Worldwide Forums | Help | Site Map

telling the difference between zero rows returned and failure

lkrubner@geocities.com
Guest
 
Posts: n/a
#1: Jul 17 '05

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


Janwillem Borleffs
Guest
 
Posts: n/a
#2: Jul 17 '05

re: telling the difference between zero rows returned and failure


lkrubner@geocities.com wrote:[color=blue]
> Suppose I make a call to MySql and zero rows come back. How do I tell
> the difference between zero rows and failure?[/color]

By calling mysql_error() like this:

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


JW



Daniel Tryba
Guest
 
Posts: n/a
#3: Jul 17 '05

re: telling the difference between zero rows returned and failure


lkrubner@geocities.com wrote:[color=blue]
> Suppose I make a call to MySql and zero rows come back. How do I tell
> the difference between zero rows and failure?[/color]

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.

Dani CS
Guest
 
Posts: n/a
#4: Jul 17 '05

re: telling the difference between zero rows returned and failure


lkrubner@geocities.com wrote:[color=blue]
> Suppose I make a call to MySql and zero rows come back. How do I tell
> the difference between zero rows and failure?
>[/color]

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.
Closed Thread