php-general | 2001032
Date: 03/29/01
- Next message: Boget, Chris: "RE: [PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Previous message: KPortsmout <email protected>: "Re: [PHP] Tough One"
- In reply to: Boget, Chris: "[PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Next in thread: Terry Romine: "[PHP] Re: [PHP-DB] Re: [PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Reply: Terry Romine: "[PHP] Re: [PHP-DB] Re: [PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Doesn't the command return 1 or 0 in success or failure?
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 ........
On Thu, 29 Mar 2001, Boget, Chris wrote:
> > i was just wondering what you guys do to check if a wquery
> > suceeded or not?
> > I know about mysql_num_rows() and mysql_affected_rows(), just
> > wondered what
> > you guys do?
>
> I do this:
>
> $result = mysql( $dbname, $query );
> if(( $result ) && ( mysql_errno() == 0 )) {
> // query was successful
> if( mysql_num_rows( $result ) > 0 ) {
> // do your stuff here...
>
> } else {
> echo "Successful query returned no rows";
>
> }
> } else {
> echo "Query failed: " . mysql_error() . "<br>\n";
>
> }
>
> There is a difference between a "successful query" and
> a query that returns 0 rows and should be handled
> differently, typically. Depending on what you are doing,
> you might not care -- 0 rows = unsuccessful query.
> However, in my case, I want to know if a query was
> malformed, contained erroneous data that's throwing
> mySQL off or whatever. These types of errors will
> return 0 rows as well.
>
> Chris
>
-- 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>
- Next message: Boget, Chris: "RE: [PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Previous message: KPortsmout <email protected>: "Re: [PHP] Tough One"
- In reply to: Boget, Chris: "[PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Next in thread: Terry Romine: "[PHP] Re: [PHP-DB] Re: [PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Reply: Terry Romine: "[PHP] Re: [PHP-DB] Re: [PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

