fetchrow_hashref
working fine, but when i use fetchrow_array getting following Error.
#!/usr/bin/perl
use warnings;
use DBI;
$DB_name = 'database';
$DB_user = 'root';
$DB_pwd = '';
my $dsn = 'dbi:mysql:avm:localhost:3306';
$dbh = DBI->connect($dsn,"$DB_user","$DB_pwd");
print "\nConnection error: $DBI::errstr\n\n";
$sth = $dbh->prepare("SELECT * FROM tblmanufacturer");
$sth->execute();
while ( ($id,$name) = $sth->fetchrow_array() )
{
print "$id\t\t $name \n";
}
$sth->finish();
$dbh->disconnect();
DBD::mysql::st fetchrow_array failed: fetch() without execute() at
I always use "die" on error at both "execute" and "prepare".
$sql = $dbh->prepare( $query ) or die "Unable to prepare $query" . $dbh->errstr;
$sql->execute() or die "Unable to execute '$query'. " . $sql->errstr;
Check the return value of execute()
and/or print "$DBI::errstr\n\n"
and see if execute is failing.
print $sth->execute(),"\n";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With