in reply to SQL Questions
Have you looked at fetchrow_hashref()? Each row is returned as a hash reference, where the column names are the keys and the DB column values are the values.
The only caveat is that it's not guaranteed to return a unique reference each time, so you need to copy the results; e.g.:
my $sql = "SELECT * FROM whatever"; my $sth = $dbh->prepare($sql); $sth->execute(); my $row; my $save_it; while (defined($row = $sth->fetchrow_hashref())) { $save_it = {}; %$save_it = %$row; # Need to save each hashed row ($save_it) now too ... }
That example assumes you're storing all rows somewhere (saving off $save_it somehow). For a single row, do the one fetch, copy the hash and return it or whatever.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: SQL Questions
by runrig (Abbot) on Jul 08, 2002 at 17:35 UTC |