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

Umar Cheema umar at drizzle.com
Mon Feb 10 12:01:53 CST 2003


Usually I try to keep my hashes consistent in terms of case. I'll either 
have all keys/fields uppercase or all of them lower case, except when 
accommodating a specific request, of course. So when querying a database I 
force my field names to be lower case in the hash:

my $row = $sth->fetchrow_hashref('NAME_lc');




On 10 Feb 2003, Dan Ebert wrote:

> 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.
> 
> Dan.
> 
> 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} .
> > 
> _____________________________________________________________
> Seattle Perl Users Group Mailing List  
> POST TO: spug-list at mail.pm.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, U-District, Seattle WA
> WEB PAGE: www.seattleperl.org
> 





More information about the spug-list mailing list