Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl dbi sqlite 'select * ..' only returns first elem

got a problem with perl dbi sqlite.

I have set up a database (and checked it with sqlite command line). Now i want to search in this database, which did not work.

So i tried to just do a 'SELECT *' this prints only the first element in the database, but not as it should everything in this table.

I think the error that causes the select * to fail is the same that prevents me from using "like %..%" stuff.

This is the relevant code, if the code is correct and the database table seems good what else could have caused the problems ?

 my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","") || die "Cannot connect: $DBI::errstr";

my $sth = $dbh->prepare('SELECT * FROM words');
$sth->execute;
my @result = $sth->fetchrow_array();


foreach( @result) {
    print $_;
}
like image 558
user1203092 Avatar asked Apr 10 '26 04:04

user1203092


1 Answers

fetchrow_array() only fetches one row.

Try

while ( my @row = $sth->fetchrow_array ) {
  print "@row\n";
}
like image 191
Secoe Avatar answered Apr 12 '26 19:04

Secoe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!