in reply to Rows Count Issue Help!
You didn't say which field the count was in, and you didn't close your statement handle (which you need to do if you don't read to exhaustion). You also have code that will never be called under RaiseError=>1, or missing error handling under RaiseError=>0.
Fixed:
my $sth = $dbh->prepare(" SELECT COUNT(DISTINCT all_id) AS cnt FROM users "); $sth->execute(); my $count = $sth->fetchrow_hashref()->{cnt}; $sth->finish();
Simplified:
my $sth = $dbh->prepare(" SELECT COUNT(DISTINCT all_id) FROM users "); $sth->execute(); my $count = $sth->fetchrow_array(); $sth->finish();
Simplified further:
my $count = $dbh->selectrow_array(" SELECT COUNT(DISTINCT all_id) FROM users ");
In all cases, RaiseError=>1 is assumed (although it's trivial to handle RaiseError=>0 in the last case).
|
|---|