in reply to if (empty record set)
A general blindness?
What this poor fellow was asking is what to do in case of an empty record set.using $sth->rows is dead wrong. rows is used in non-select statements.
Somebody suggested using $sth->fetchrow_arrayref in void context, without catching the result anywhere. Wow!The simple way is
$sth->execute(); my $recordset = $sth->fetchall_arrayref(); if (@$recordset) { # there are records. Do something here } else { # empty recordset. Do something else. }
Or, if you don't want to get all records at once
my $found = 0; while (my $rec = $sth->fetchrow_arrayref()) { #do something $found = 1; } unless ($found) { # recordset was empty. # do something else }
|
|---|