-
Notifications
You must be signed in to change notification settings - Fork 1
/
DB.py
33 lines (25 loc) · 907 Bytes
/
DB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import MySQLdb
class DB:
""" This is mbasically a mysql_ping() hack, because MySQLdb unhelpfully lacks basic keepalive support """
conn = None
def connect(self):
#global conn
self.conn = MySQLdb.connect(host = 'db.somehost.com',
user = 'dcorbe',
passwd = 'xxXXxx',
db = 'mlm')
#conn = self.conn
self.conn.autocommit(True)
def cursor(self):
if self.conn:
self.conn.ping(True)
try:
return self.conn.cursor()
except (AttributeError, MySQLdb.OperationalError):
self.connect()
return self.conn.cursor()
def getInstance():
global conn
if conn == None:
conn = DB()
return conn