Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How do i check if a mysql database is empty?

by Itatsumaki (Friar)
on Nov 27, 2003 at 08:02 UTC ( #310491=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://310491]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2020-05-25 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (143 votes). Check out past polls.

    Notices?