selectrow_hashref()
$dbh->selectrow_hashref($sql_statement[, \%attri, @values])
This function returns a reference to a hash of one row from
the results of an SQL statement given. This method combines
prepare(),
execute(), and
fetchrow_hashref(). However, a statement
handle could be given. Attributes that may be given for a statement
handle may be provided in a hash for the second argument of this
method. If placeholders are used in the SQL statement, their values
may be given as an array for the third argument.
Here is an example:
...
my $sql_stmnt = "SELECT title, author
FROM books WHERE book_id = ?";
my $book_ref = $dbh->selectrow_hashref($sql_stmnt, undef, '1234');
print "$book_ref->{title} by $book_ref->{author} \n";Notice that this method captures the names of the columns as the keys to the values in the hash generated. Notice also that because only one row is captured, a control statement is unnecessary.