On Sat, Sep 22, 2001 at 06:37:32PM -0500, [EMAIL PROTECTED] wrote:
> this one seems to puzzle me on how to avoid an unnecessary db error. I
> need to run a tally count on a couple tables, and if there isn't any data
> in the table it displays the dbError, altho there isn't technical any
> syntax error in the query other then no return or results.
> $sqlquery = qq|SELECT COUNT(*) FROM expired WHERE expdate < CURDATE()|;
> $expire = $dbh->selectrow_array($sqlquery) or dbError();
>
> Is this way to avoid the dbError() if the query returns no results(which
> would indicate a '0' tally.
If there is an error, selectrow_array() will return an empty list, which
will set $expire to undef. Thus, instead of checking whether $expire is
true, you should check whether it is defined.
defined( $expire = $dbh->selectrow_array($sqlquery) ) or dbError();
Ronald