Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Problem managing persistent database connections in modulesby LanceDeeply (Chaplain) |
on Jul 25, 2002 at 20:54 UTC ( [id://185338]=note: print w/replies, xml ) | Need Help?? |
mp- Here's one way to manage your connections. You can create a wrapper class around the actual connection. i've done some *basic* connection management for Win32::ODBC. (1) have a single place in the code where all connections are made so that it is easy to change connection parameters later; I kept a default connection string in the dbConnectionClass. All new connections that do not have a connection string specified use the default connection string. (2) have connections be persistent (Apache::DBI); The (Win32::ODBC) connections persist in connection pools hashed on their connectionString. a pool is an array of db connections. (3) have one point in each module at which the connection is made for that module; I propose that you call new dbConnection liberally and let the underlying connection pooling manage the number of connections kept open. (4) in a given process, share all connections (i.e. connection is a singleton or is managed by a singleton); yep... (5) Have modules that require database access manage their own connection rather than require that a database handle be passed to them; yes. each method that requires db access should just create a new dbConnection. (you dont care wether a new one is really created or one is pulled from a pool)
Hope this was helpful!
In Section
Seekers of Perl Wisdom
|
|