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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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. |