I use MySQL-python (use freshmeat to find it).
I've written my own class to use around it which looks a lot like:
class MyDBClass:
def __init__(self):
self.db = None
self.dbname, self.user, self.passwd = None, None, None
def connect(self, user = "", passwd = "", dbname = ""):
"""Connect to the database"""
# Allow overrides during connect call:
if user: self.user = user
if passwd: self.passwd = passwd
if dbname: self.dbname = dbname
# Make sure the info is valid
if not self.user or not self.passwd:
raise MyDBExcept()
if not self.dbname:
self.db = MySQLdb.connect(user=self.user,
passwd=self.passwd)
else:
self.db = MySQLdb.connect(user=self.user,
passwd=self.passwd, db=self.dbna
me)
def doquery(self, QUERY, DEBUG = 0):
"""Run the query against the database"""
if not self.db:
return (-1, None)
if DEBUG:
print QUERY + ";"
cursor = self.db.cursor()
try:
count = cursor.execute(QUERY)
except IntegrityError:
count = 0
if not count:
# print "No results for " + QUERY
return (0, None)
results = cursor.fetchall()
return (count, results)
--
Michael T. Babcock
C.T.O., FibreSpeed Ltd.
http://www.fibrespeed.net/~mbabcock
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
- interface to python? vishnu mahendra
- Re: interface to python? Fred van Engen
- Re: interface to python? Paul DuBois
- Re: interface to python? Michael T. Babcock
- Re: interface to python? Roger Baklund
- Re: interface to python? Rog11228