
October 6th, 2003, 11:53 AM
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
mod_python & MySQLdb question
Consider the following code:
Code:
#test.py
import MySQLdb
def process(req, value):
db = MySQLdb.connect(host="localhost", user="foo", passwd="bar", db="pythondb")
cursor = db.cursor()
... do something with database connection ...
return something
When you access this file through a browser with /process?value=something appended, mod_python imports it, executes the process function with value as a parameter and displays whatever you returned. My question is, would it be a good idea to move the part where I connect to the database to module(global) level ? Then it wouldn't be neccesary to reconnect every time the process function is called.
Last edited by Cuboidz : October 6th, 2003 at 11:57 AM.
|