DBD::mysql::st fetchrow_array failed: fetch() without execute()
This is the error I'm getting on a simple script. I don't understand what I'm doing wrong. Can someone please help me understand what I'm doing wrong?
#!/usr/bin/perl
use strict;
use DBI;
# Connect to the database.
my $host = "host.domain.com";
my $database = "mail";
my $user = "readonly";
my $password = "***";
my $dsn = "DBI:mysql:database=$database;host=$host";
my $dbh = DBI->connect($dsn, $user, $password);
if (! $dbh) {
die(sprintf('error'));
}
my $sql = qq`SELECT username from accountuser`;
my $sth = $dbh->prepare($sql);
$sth->execute();
while (my @record = $sth->fetchrow_array()) {
my $numrows = $sth->rows();
my $command = "/usr/lib/cyradm-imapd/squatter -v -s -r ";
for (my $i=0; $i<$numrows; $i++) {
exec $command $record[$i];
}
$sth->finish();
}
$dbh->disconnect();
Thanks in advance.
This is the error I'm getting on a simple script. I don't understand what I'm doing wrong. Can someone please help me understand what I'm doing wrong?
#!/usr/bin/perl
use strict;
use DBI;
# Connect to the database.
my $host = "host.domain.com";
my $database = "mail";
my $user = "readonly";
my $password = "***";
my $dsn = "DBI:mysql:database=$database;host=$host";
my $dbh = DBI->connect($dsn, $user, $password);
if (! $dbh) {
die(sprintf('error'));
}
my $sql = qq`SELECT username from accountuser`;
my $sth = $dbh->prepare($sql);
$sth->execute();
while (my @record = $sth->fetchrow_array()) {
my $numrows = $sth->rows();
my $command = "/usr/lib/cyradm-imapd/squatter -v -s -r ";
for (my $i=0; $i<$numrows; $i++) {
exec $command $record[$i];
}
$sth->finish();
}
$dbh->disconnect();
Thanks in advance.