MySQL DB-Api

Robert Rawlins robert.rawlins at thinkbluemedia.co.uk
Tue Mar 11 07:23:41 EDT 2008


Good morning list.

 

I'm in the process of learning my way around the DB-API module for MySQL and
wanted to come and get some advice on how you all manage your database
connections and cursors.

 

Within my applications I'll have many classes which access the database, I'm
wondering to what level I should extract the database connection. 

 

Should I create a new database connection and close it for every method
which calls the database? Should I create the connection/cursor  to the DB
when I construct the class and place the cursor in the self scope? Or should
I create a application wide connection/cursor to the database and inject the
cursor into all the classes which require it?

 

All classes within the application access the same database so at the moment
I'm leaning towards creating an application wide connection and cursor and
then injecting it into classes which require database access, does that
sound like a fair plan?

 

I'm just interested to learn how you are managing this.

 

Thanks guys,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080311/2e13ea0b/attachment.html>


More information about the Python-list mailing list