Home : Dokumentation : 1.3.6 Dokumentation : Tips & Tricks
Google Web perl.apache.org

 
Home
 
Features
 
Einführung
 
Dokumentation
 
README
 
README.v2
 
Konfiguration
 
Embperl
 
Embperl::Object
 
Embperl::Form::Validate
 
Embperl::Syntax
 
Embperl::Recipe
 
Embperl::Mail
 
1.3.6 Dokumentation
 
HTML::Embperl
 
HTML::EmbperlObject
 
HTML::Embperl::Mail
 
HTML::Embperl::Session
 
Tips & Tricks
 
FAQ
 
DBIx::Recordset
 
Installation
 
Download
 
Support
 
Änderungen
 
Wiki
 
Weitere Infos
 
Hinzufügen Infos
 
Login

    Stable 2.4.0
    Beta 2.5.0_3
Unterstützen Sie Embperl! Mehr...
Handling Queries in DBI
[ << Prev: Global Variables Via Namespaces ] [ Content ] [ Next: Handling Exits >> ]

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).


[ << Prev: Global Variables Via Namespaces ] [ Content ] [ Next: Handling Exits >> ]

© 1997-2012 Gerald Richter / ecos gmbh