in reply to Get a hash object from a database with DBI for use with HTML::Template
intomy $stmt = "SELECT * FROM $table WHERE $key_col = '$key_val'"; my $sth = $dbhandle->prepare( $stmt ); $sth->execute();
my $stmt = "SELECT * FROM $table WHERE $key_col = ?"; my $sth = $dbhandle->prepare( $stmt ); $sth->execute($key_val);
intomy $ref = $sth->fetchall_arrayref(); $sth->finish(); return map { $_->[$name_col] => $_->[$val_col] } @$ref;
my $ref = $sth->fetchall_hashref([$name_col,$val_col]); $sth->finish(); return map {@$_} @$ref;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) 2Re: Get a hash object from a database with DBI for use with HTML::Template
by jeffa (Bishop) on Aug 04, 2002 at 17:12 UTC |