[Dancer-users] Using persistent DB connections in Dancer::Tutorial
Puneet Kishor
punk.kish at gmail.com
Sat Jan 8 15:56:57 CET 2011
Gurunandan Bhat wrote:
> If I rewrite connect_db as:
>
> my $dbh;
> sub connect_db {
>
> if (! defined $dbh) {
> $dbh = DBI->connect("dbi:SQLite:dbname=".setting('database')) or
> die $DBI::errstr;
>
> }
> return $dbh;
> }
>
> will the application use a single connection for all connections under
> all perl webservers (in-built, mod_perl, Starman, Twiggy etc.).
I am interested in a definitive and clear answer as well. I tried the
above method a while back, and kept on getting errors on transactions (I
am using SQLite).
Since I am using Apache, I added `PerlModule Apache::DBI` to my
httpd.conf, and went back to a simple $dbh creation instead of checking
for `defined $dbh`
Knowing the correct way to implement this, perhaps even the way*s* for
different servers (I am assuming different web servers might have
different ways of implementing persistent connections) would be
tremendously helpful.
> If that is true, a line to that effect in an appropriate place in the
> tutorial would emphasize the persistent features of the solution.
>
> Also, are any hooks run when the application instance is destroyed? If
> there are, implementing a graceful closing of open DB connection(s)
> might provide a valuable lesson in the Tutorial.
>
> Thank you.
>
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
--
Puneet Kishor http://punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Fellow http://creativecommons.org/about/people/fellows#puneetkishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
---------------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
===========================================================================
More information about the Dancer-users
mailing list