in reply to fetchrow_array return value

If you use fetchrow_array() like that then if there are one or more rows returned then the first one is lost, because you threw it away in the if().

Why not do something like:

my $found = 0; while(my @row = $sth->fetchrow_array) { ++$found; ... process @row ... } if(!$found) { ... no rows found ... }
As for using $sth->rows(), the problem is that for most database engines the number of rows affected by a SELECT query can only be determined once all of the rows have been fetched...