Re: RE: [PHP-DB] Best way to check if a query succeeded
| From: | Stuart J. Browne | Date: | Fri, 30 Mar 2001 01:41:42 +0000 |
| Subject: | Re: RE: [PHP-DB] Best way to check if a query succeeded | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-46216@lists.php.net to get a copy of this message | ||
> > 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
}
?