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
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
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
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!