php-general | 2001032

Re: [PHP] RE: [PHP-DB] Best way to check if a query succeeded From: Stuart J. Browne (stuart <email protected>)
Date: 03/29/01

> > Doesn't the command return 1 or 0 in success or failure?
>
> Not 1 or 0. It returns 0 or some other value. Almost the same,
> but not quite.
>
> > You may not have a result
> > Probably wrong but something like
> > if (mysql_query($query)) {
> > } else {
> > }
> > or you could die out mysql_query($query) or die ........
>
> You could do that. But once you run the query, that's it. You'll
> have nothing to use with any of the other mysql functions because
> you need to pass to them the value that mysql() returns. So while
> the above might tell you whether or not the query succeeded, that's
> all you would get out of it.

Wouldn't doing it like this however be ok:

    if ($result = mysql_query($query)) {
        ; success, have $result
        if (mysql_num_rows($result) > 0) {
            ; have data to play with
        } else {
            ; dont
        }
    } else {
        ; wasn't successful, don't have result
    }

?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>