telling the difference between zero rows returned and failure

This is a discussion on telling the difference between zero rows returned and failure within the PHP Language forums, part of the PHP Programming Forums category; Suppose I make a call to MySql and zero rows come back. How do I tell the difference between zero ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-30-2004
lkrubner@geocities.com
 
Posts: n/a
Default telling the difference between zero rows returned and failure


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

Reply With Quote
  #2 (permalink)  
Old 12-30-2004
Janwillem Borleffs
 
Posts: n/a
Default Re: telling the difference between zero rows returned and failure

lkrubner@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



Reply With Quote
  #3 (permalink)  
Old 12-30-2004
Daniel Tryba
 
Posts: n/a
Default Re: telling the difference between zero rows returned and failure

lkrubner@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.

Reply With Quote
  #4 (permalink)  
Old 12-30-2004
Dani CS
 
Posts: n/a
Default Re: telling the difference between zero rows returned and failure

lkrubner@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.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:46 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0