Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use $sth->fetchrow_hashref, $sth->fetchrow_arrayref and $sth->fetchrow_array?

Tags:

perl

dbi

I know that:

  • $sth->fetchrow_hashref returns a hashref of the fetched row from database,
  • $sth->fetchrow_arrayref returns an arrayref of the fetched row from database, and
  • $sth->fetchrow_array returns an array of the fetched row from database.

But I want to know best practices about these. When should we use fetchrow_hashref and when should we use fetchrow_arrayref and when should we use fetchrow_array?

like image 612
user380979 Avatar asked Sep 09 '10 13:09

user380979


1 Answers

You could do worse than read DBI recipes by gmax.

It notes, among other things:

The problem arises when your result set, by mean of a JOIN, has one or more columns with the same name. In this case, an arrayref will report all the columns without even noticing that a problem was there, while a hashref will lose the additional columns

like image 83
Ed Guiness Avatar answered Nov 15 '22 19:11

Ed Guiness