[DB-SIG] Managing My Database Connections

Andy Todd andy47 at halfcooked.com
Wed Mar 19 10:08:31 CET 2008

Gerhard Häring wrote:
> Robert Rawlins - Tamed Technology wrote:
>> Essentially I only have a single database attached to my application 
>> but I’m looking for the best way to handle its connection so thought I 
>> would come and get your thoughts and opinions.
>> Within my applications I’ll have many classes which access the 
>> database, I’m wondering to what level I should extract the database 
>> connection. [...]
> Be sure to wrap the actual "getting the connection object".
>> Should I create a new database connection and close it for every 
>> method which calls the database? Should I create the connection  to 
>> the DB when I construct the class and place the cursor in the self 
>> scope? Or should I create an application wide connection to the 
>> database and inject the connection into all the classes which require 
>> it? [...]
> That's what I'd do. But I'd not inject it and rather just get it (like 
> with get_con() in my example code).
> I've attached example code that shows how DB-API database access can be 
> simplified.
> -- Gerhard

Nice. I have a module that abstracts getting the initial connection and 
attempts a standard URI scheme;


Somewhere in the combination is a 'simplified' DB-API fighting to get 
out ...

 From the desk of Andrew J Todd esq - http://www.halfcooked.com/

More information about the DB-SIG mailing list