fetchrow_hashref () is slower than using bind_columns (), with which you can achieve the same:
my %rec; my $sth = $dbh->prepare ("select * from foo"); $sth->execute; $sth->bind_columns (\@rec{@{$sth->{NAME_lc}}}); while ($sth->fetch) { print "foo.c_foo = $rec{c_foo}\n"; }
Some proof with a table with 8 fields and and 62684 records:
cmpthese (5, { hashref => sub { my $sth = $dbh->prepare ("select * from ll_go"); $sth->execute; 1 while my $h = $sth->fetchrow_hashref; }, bindcol => sub { my %rec; my $sth = $dbh->prepare ("select * from ll_go"); $sth->execute; $sth->bind_columns (\@rec{@{$sth->{NAME_lc}}}); 1 while $sth->fetch; }, }) => perl bench.pl Rate hashref bindcol hashref 1.31/s -- -76% bindcol 5.49/s 320% --
In reply to Re: DBI : Get Column name and Value in hash
by Tux
in thread DBI : Get Column name and Value in hash
by vinoth.ree
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |