RE: [phplib] test for database SQL success or failure From: Howard Ha (howardh <email protected>)
Date: 03/13/01

Personally I would avoid using $db->next_record() without first a check to
see whether there are rows returned, because otherwise you get an error
message (At least with MySQL you do).

If you are running a select query, use

if ($db->num_rows() > 0) {}

When running an insert/delete/update query you can use

$db->affected_rows()

Except that if the update does nothing your affected rows will be 0 but your
result handler will be successful.

> -----Original Message-----
> From: Layne Weathers [mailto:layne <email protected>]
> Sent: Tuesday, March 13, 2001 8:25 AM
> To: phplib <email protected>
> Subject: Re: [phplib] test for database SQL success or failure
>
>
> > I'm looking for a way to test whether or not a call to phplib query
> > function has succeeded or failed.
> >
> > if i call the 'query' function ie. $db->query( "SQL" );
> >
> > what can I do next to test the "pass" or "fail" of the SQL statement.
>
>
> Depending on the circumstances
>
> if($db->num_rows()) { ... }
>
> or
>
> if($db->next_record()) { ... }
>
>
> You could also use a preliminary query to find the number of
> matching rows.
>
> $db->query("select count(*) from table where ...");
> $db->next_record();
> if($db->f(0)) { ... }
>
>
>
> Layne Weathers
> Ifworld, Inc.
> layne <email protected>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: phplib-unsubscribe <email protected>
> For additional commands, e-mail: phplib-help <email protected>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>