in reply to sql record sets

Not sure about the DBI query function, but this should do the trick:
my $sth = $dbh->prepare("SELECT * FROM foo"); $sth->execute(); while (my $row = $sth->fetchrow_arrayref()) { # Use @$row like $row->[0], $row->[1], etc. } $sth->finish(); # Important!


Update:
In response to your repeating question, you might want to look at the functions that can load in the entire result set, so that you can go over it as many times as you like.
my $rows = $dbh->selectall_arrayref("SELECT * FROM foo"); # Now @$rows contains all the row data. # Use @$rows like $rows->[$row_number]->[$column_number]... foreach my $row (@$rows) { # ...or @$row like $row->[$column_number] } # Repeat as required, as long as $rows is still defined. # $sth->finish(); # Update per pope (Not required, no $sth defined)

Replies are listed 'Best First'.
Re: Re: sql record sets
by pope (Friar) on Sep 16, 2002 at 08:30 UTC
    finish() is not necessary here, since all rows have been fetched. This is necessary in a case where after fetching particular rows, you want to discard the rest.