Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

(dkubb) Re: (2) HTML::Template, DBI and <TMPL_LOOP>'s

by dkubb (Deacon)
on Jan 04, 2004 at 00:02 UTC ( #318561=note: print w/replies, xml ) Need Help??


in reply to HTML::Template, DBI and <TMPL_LOOP>'s

I believe the technique I was using was removed from DBI about 3 months after my post. It was replaced with a more elegant (IMHO) system that can replicate the same results with newer versions of DBI.

In the earlier example I was trying get DBI to return an array reference of hash references with a single DBI method call. I don't see the need to break something up into multiple steps (prepare/execute/fetchall_arrayref) if DBI provides an all-in-one "utility method" that does these things underneath. Plus, as jeffa mentioned, it cuts down the number of places where you need to specify the names of the columns -- which is convenient if you ever need to make changes.

Here's how I would do it using a more recent version of DBI:

my $statement = q{ SELECT id , title FROM movie }; # $template is an HTML::Template object $template->param( movies => $dbh->selectall_arrayref($statement, { Slice => {} }), );
Dan Kubb, Perl Programmer

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://318561]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2022-12-07 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?