Name

fetchrow_arrayref( )

Synopsis

$statement_handle->fetchrow_arrayref( )

This returns a reference to a place in memory containing an array of one row from the results of a statement handle. There are no arguments for this function. It’s synonymous with fetch( ).

...
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.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.