Handling the Resultset
After we have run a query and created a resultset, we need to process it. Table 12.2 shows an overview of the DBI methods that we can use to handle the resultset of the query.
DBI Method | Meaning |
---|---|
$hash_ref = $sth->fetchrow_hashref; | Reference to hashed array containing one row of resultset keyed by column name |
@row_ary = $sth->fetchrow_array; | Array containing one row of resultset |
$ary_ref = $sth->fetchrow_arrayref; | Reference to object containing one row of resultset |
$ary_ref = $sth->fetchall_arrayref; | Reference to object containing all rows of resultset |
$ary_ref = $dbh->selectall_arrayref(); | Prepare and execute query, return reference to object containing all rows of resultset, and finish ... |
Get Sams Teach Yourself MySQL in 21 Days, Second Edition 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.