Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instantiate Class DB Connection

Status
Not open for further replies.

bam720

Technical User
Sep 29, 2005
289
US
I am having some trouble controlling my database connection. I have one module DbConnection.py that handles connecting to the database. I call it and get returned the database handle object just fine. as such

Code:
dbh = DbConnection.new()

I have another module to handle certain queries (this is a multi step process each being call as cgi scripts).

Code:
Order.SetDatabaseHandle(dbh)

The trouble I am having is in Order.

Code:
#
# Class variables
#
dbh # Database Handle [COLOR=red]I need to instantiate the handle class wide[/color]

def SetDatabaseHandle(data):
  dbh = data

def Create(data):
  cursor = dbh.cursor()

How do I instantiate it class wide? I could just create a connection wherever I call the create function but don't want to have too many open connections at any given time. Any help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top