package Tie::STHRows; use base Tie::Array; sub TIEARRAY { my $class = shift; my $sth = shift; die "You must pass a statement handler!" unless ref($sth) eq "DBI::s +t"; my %row; $sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } )); bless ([$sth,\%row],$class); } sub FETCH { my $self = shift; $self->[0]->fetch; return +{ %{$self->[1]} }; # per tye's suggestion } sub FETCHSIZE { ${+shift}[0]->rows; }; sub DESTROY { ${+shift}[0]->finish; } 1; __DATA__ sample snippet for how it works: $sth = $dbh->prepare(...); $sth->execute; tie @loopdata, Tie::STHRows, $sth; $template->param(LOOPDATA => \@loopdata); and your template: <TMPL_LOOP NAME=LOOPDATA> ... </TMPL_LOOP>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: Tie::STHRows for HTML::Template loops
by jeffa (Bishop) on Jul 30, 2003 at 13:51 UTC | |
by antirice (Priest) on Jul 30, 2003 at 14:03 UTC | |
|
Re: Tie::STHRows for HTML::Template loops (extra copy)
by tye (Sage) on Jul 30, 2003 at 16:20 UTC |