fetchrow_arrayref()
$sth->fetchrow_arrayref()This function returns a reference to a place in memory
containing an array of one row, the next row from the results of a
statement handle. There are no arguments for this function. Null
values retrieved are returned as undefined. An empty value is returned
when there is an error or when there are no more rows remaining in the
results set. Therefore, if used in a flow control statement such as
while, the empty value returned will end the loop
statement. Here is an example:
...
my $sql_stmnt = "SELECT title, author FROM books";
my $sth = $dbh->prepare($sql_stmnt);
$sth->execute();
while (my $book = $sth->fetchrow_arrayref()) {
my ($title, $author) = @$book;
print "$title by $author \n";
}
$sth->finish();Notice that fetchrow_arrayref() is
reused at the beginning of each pass through the
while statement. This is because a reference to one
row is retrieved at a time. The same reference is used for each row
retrieved: the array is replaced with each loop. If you want to use
array references, you might want to use
fetchall_arrayref() instead.