http://www.perlmonks.org?node_id=310491


in reply to How do i check if a mysql database is empty?

Try this:

my $sql = 'SELEcT Email FROM foo'; my $sth = $dbh->prepare($sql); $sth->execute(); if (my $email = $sth->fetchrow_array()) { print "$email\n"; } else { print "Database Empty\n"; } $sth->finish(); $dbh->disconnect();

Update: I think you want to print out all e-mails, like this:

my $sql = 'SELECT Email FROM foo'; my $sth = $dbh->prepare($sql); $sth->execute(); if (my $email = $sth->fetchrow_array()) { print "$email\n"; while ($email = $sth->fetchrow_array()) { print "$email\n"; } } else { print "Database empty\n"; }

Update 2: Fixed typo in first solution.