If you are like me, you probably use DBI extensively to enable your
dynamic websites. I have found the cleanup of queries to be onerous -
e.g. calling finish() on queries. If you don't do that, then you tend
to get warnings in your error log about unfinished queries. What I do these days is use a global hash, called e.g. %domain::query
(see the previous section for using namespaces to safely implement
global variables). Then, whenever I create a query, I use this
variable. For example: $domain::query{first_page} = $domain::dbh->prepare (qq{
SELECT *
FROM pages
WHERE page = 1
});
$domain::query{first_page}->execute();
my $first_page = $domain::query{first_page}->fetchrow_hashref(); This little pattern, I find, makes all my queries easier to read and
keep track of. You give each one a name in the %domain::query hash
that makes sense. Then, at the end of each request, in the
/cleanup.html file, you can do something like this: while (($name, $query) = each (%domain::query))
{
$query->finish();
}
$domain::dbh->disconnect(); Once again, this method is not really the "official" way of doing
things in Embperl. You should use the Request object to pass around
global variables if you're not comfortable with the risks involved
with namespaces (e.g. conflicting websites on the same web server).
|