Re: can i set up a mysql db connection as a class ?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: can i set up a mysql db connection as a class ?

From: *binarystar* <binarystar.@binarystar.org>
Date: Fri Apr 28 2006 - 06:00:20 CEST

that's definitely the way to go ..

-create a database_object
-initialise at start up
-then pass the database object to other classes as needed ...

If you want to get really fancy have a look at some ORM's ... I think
there is a Python one called SQLObject?

nephish@xit.net wrote:
> hey there,
> i have a huge app that connects to MySQL. There are three threads that
> are continually connecting and disconnecting to the db. The problem is,
> if there is an error, it faults out sometimes without closing the
> connection. i connect like this.
> db = MySQLdb.connect(host="localhost", user="MyUser",
> passwd="MyPassword", db="Stuff")
> cursor=db.cursor()
>
> then i use the cursor.execute("SELECT yadda yadda
>
> my question is, is there a way i can set up a global connection so that
> when the program loads, it connects once, then stays connected ? maybe
> i could assign instances of the cursor ?
>
> please someone let me know if you have any good ideas
>
> sk
>
Received on Mon May 1 00:34:57 2006