Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DB():
- db = None
- def __init__(self, mysqlhost, mysqluser, mysqlpass, mysqldb):
- self.mysqlhost = mysqlhost
- self.mysqluser = mysqluser
- self.mysqlpass = mysqlpass
- self.mysqldb = mysqldb
- def connect(self):
- self.db = MySQLdb.connect(host=mysqlhost, user=mysqluser, passwd=mysqlpass, db=mysqldb)
- def query(self, sql):
- try:
- cursor = self.db.cursor()
- cursor.execute(sql)
- except(AttributeError, MySQLdb.OperationalError):
- self.connect()
- cursor = self.db.cursor()
- cursor.execute(sql)
- return cursor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement