Gossamer Forum
Home : General : Perl Programming :

DBI count

Quote Reply
DBI count
Hi,

I'm just wondering, does anyone know why this would return "1" even if URL = xxx doesn't exist in the InternalPages table?

BTW - $dbh is being opened fine (thats not the issue, it just returns 1 when I would expect it to return 0)

Code:
sub check_been_spidered_already {

my $url = $_[0];

my $sth = $dbh->prepare(qq|SELECT COUNT(*) FROM InternalPages WHERE URL = ?|) || die $DBI::errstr;
$sth->bind_param(1,$url);

my $count = $sth->execute() || die $DBI::errstr;

print qq|SELECT COUNT(*) FROM InternalPages WHERE URL = $url \n|;

print "COUNT: $count \n";

return $count;

}

Probably missing something really silly - I just get too used to using GT::SQL's count() function Tongue

TIA

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] DBI count In reply to
Hi,

Anyone ?

I've even tried:

Code:
sub check_been_spidered_already {

my $url = $_[0];


my $dbh = DBI->connect( 'dbi:mysql:spidertest',
'spidertest',
'spidertest',
) || die $DBI::errstr;


# add it to the DB
my $sth = $dbh->prepare(qq|SELECT COUNT(*) FROM InternalPages WHERE URL = "$url"|) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
my $count = $sth->rows || 0;

print "COUNT: $count \n";

$sth->finish();
$dbh->disconnect();

return $count;

}

..but it still gives "1" as a result, even though it shouldn't (should give "0")

TIa

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates