in reply to Re: DBI performance problem
in thread DBI performance problem
my $statement= q{ SELECT COUNT(*) FROM products WHERE nr = ? }; my $count = $dbh->selectrow_array($statement, {}, $nr);
At first glance, you're probably thinking that this returns an entire array, and will just set $count to 1 no matter what (because you're expecting it to return a one element array). Though, after further inspection of DBI.pm, you'll see that this method checks wantarray to see how it should return. If it sees that you are asking for a single scalar and not an array, it will just return the first column, of the first row, and set $count to this value.
I think that DBI::selectcol_arrayref is better when you are returning one and possibly more rows, where each row should contain a single column.
|
|---|