SPUG:using DBI::fetchrow_array(); to load another array

Dan Ebert mathin at mathin.com
Mon Feb 10 11:45:07 CST 2003

One note I'd add to this:

The hash keys are case sensitive, so you have to pay attention to the
case of the field labels ... or do a 'select Blah as blah' in your
query.  This has tripped me up a couple times where one field name was
all caps when the rest of the table's fields were lower.


On Mon, 2003-02-10 at 09:32, Creede Lambard wrote:
> On Mon, 2003-02-10 at 05:04, Chris Wilkes wrote:
> > Later on in the perldoc for DBI it has
> > 	$ary_ref  = $sth->fetchall_arrayref;
> > which I think is what you're thinking about. 
> For some reason I have better luck with fetchrow_hashref. Same general
> idea, just returns a hash reference to the row you're looking for.
> my $query = "select * from foo";
> my $sth = $dbh->prepare($query);
> $sth->execute;
> while (my $row = $sth->fetchrow_hashref()) {
>     print Dumper $row;
> }
> Members of $row are accessed by dereffing the hash, e.g. $row->{id} .

More information about the spug-list mailing list