in reply to using CGI, DBI and HTML::Template (a mini tutorial with example code)

selectall_hashref() only works in a limited number of versions of DBI (maybe 1.15 through 1.19). For the newest versions, 1.20 and greater I believe, you can get the same functionality that you are looking for like this:

selectall_arrayref($sql,{ Slice => {} });

selectall_hashref does something different in the newest versions and your old code will break.

Here's another way to process your DB output as well:

my $rows = $DBH->selectall_arrayref($sql,{ Slice=>{} }); for (@$rows) { # add key/value for Pi to every row. $_->{pi} = 3.14; }

For even lazier form re-filling, look into adding HTML::FillInForm into the mix. Then you don't even have to add the <tmpl> tags into your forms in many cases. I use this in conjuction with HTML::Template. There is as outdated tutorial on using these here. It's outdated because HTML::FormValidator has been superceded by Data::FormValidator.


Replies are listed 'Best First'.
Re: Re: using CGI, DBI and HTML::Template (a mini tutorial with example code)
by gav^ (Curate) on Feb 12, 2002 at 16:47 UTC

    Thanks for the tip, I just upgraded from 1.15 to 1.201 and found this broken. Now I'm worried as I have to make sure nobody upgrades DBI and causes all my scripts to break.


      Good Tutorial, though l have to admit l did get caught out my the selectall_hashref and after searching this site, l found an easy solution to it:
      my $table_data = $dbh->prepare($companyquery); $table_data->execute; my $arrayref = $table_data->fetchall_arrayref({}); $template->param(ROWS => $arrayref);
      Hope this helps
        This one works much better. Thanks alot for sharing it with me. I really need it