On Dec 17, 2:06pm, Tim Bunce wrote:
> Also I believe that the excellent TemplateToolkit now has a DBI plugin.
Indeed it has. Simon Matthews is the author but I don't think he's
posted it to CPAN yet. Hopefully this email will remind him. The
latest version he sent me earlier this week seems very solid.
Simply 'USE' the DBI plugin, specifying a data source and then call
the 'query' method to execute queries. An iterator is returned which
the toolkit will use to provide access to the records returned, via a
FOREACH or by explicitly calling get_first(), get_next() on the
iterator.
Here's a simple example:
[% USE DBI('dbi:mSQL:dbname') %]
[% FOREACH user = DBI.query('SELECT * FROM user') %]
* [% user.name %] [% user.email %]
[% END %]
This one uses a CGI parameter ('userid') to seed some queries:
[% USE CGI %]
[% userid = CGI.param('userid') %]
[% USE DBI('dbi:mSQL:dbname') %]
[% user = DBI.query("SELECT * FROM user WHERE id='$userid'").get_first %]
[% INCLUDE header
title = "User Profile: $user.name"
%]
<h1>[% user.name %]</h1>
[% modlist = DBI.query("SELECT * FROM module WHERE author='$userid'") %]
[% FOREACH mod = modlist %]
[% IF modlist.first %]
<h2>Modules</h2>
<ul>
[% END %]
<li><a href="[% mod.url %]">[% mod.name %]</a>
[% IF modlist.last %]
</ul>
[% END %]
[% END %]
[% INCLUDE footer %]
A
--
Andy Wardley <[EMAIL PROTECTED]> Signature regenerating. Please remain seated.
<[EMAIL PROTECTED]> For a good time: http://www.kfs.org/~abw/