Where is the dberror function? Is that part of your script?
Where ever it is, you are calling it when you get 0 results returned. Is
that what you are wanting to do? It doesn't sound like it from reading your
description. If you don't want that function called when you have 0 results,
then alter the two selectrow_array lines like this:
$active = $dbh->selectrow_array($sqlquery);
and
$expire = $dbh->selectrow_array($sqlquery);
In that case, $expire will equal 0 when the count is 0 and the dbError
function is not called when 0 rows are returned.
If you want the error returned when there really is an error, but not get an
error when 0 rows are returned, then handle the statements like this:
$sth = $dbh->prepare($sqlquery) || die "Can't prepare $sqlquery\n
$DBI::errstr";
$sth->execute() || die "Can't execute $sqlquery\n $DBI::errstr";
$active = $sth->fetchrow_array();
# do something with $active now.
Does this help?
Steve H.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Saturday, September 22, 2001 6:38 PM
To: [EMAIL PROTECTED]
Subject: Avoid Error if no results
Hi All,
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.
my $active = 0;
my $expire = 0;
$sqlquery = qq|SELECT COUNT(m.memid) FROM members m,payhistory p
WHERE p.active = 'Y' AND p.memid = m.memid|;
$active = $dbh->selectrow_array($sqlquery) or dbError();
$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.
thx's
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://www.thunder-rain.com
Tel: 1(225)686-2002
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=