my $row = selectrow_arrayref($stmt_or_sth, undef, $id); if ($row) { ... } else { # No more images ... }