in reply to DBI forgets last record

I also experienced the same problem recently--or maybe I only noticed it recently.  For me it wasn't the last record, but the first record as Zaxo suggested above.  To solve the problem I switched from a while loop to a foreach.  Below is my related code excerpt.  In this case I'm generating a hash from records from a mySQL database.  I'm also using fetchall_hashref instead of fetchrow_array.

my $sql_stmnt = "SELECT rec_id, name FROM writers"; my $dbh = DBI->connect("DBI:mysql:db:localhost","user","passwd") || die "Could not connect to database: " . DBI->errstr; my $sth = $dbh->prepare($sql_stmnt); $sth->execute(); my $results = $sth->fetchall_arrayref(); my %results; foreach my $row(@$results) { my ($key,$value) = @$row; $results{$key} = "$value"; } $sth->finish(); $dbh->disconnect();

-Spenser

That's Spenser, with an "s" like the detective.