This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
curunir/modules/mysql.py

29 lines
793 B
Python
Raw Normal View History

from . import ModuleBase
2010-05-02 21:18:09 +02:00
import MySQLdb
class Module(ModuleBase):
def __init__(self, manager):
ModuleBase.__init__(self, manager)
self.conf = manager.config['mysql']
2010-05-02 21:18:09 +02:00
self.db = False
self._connect()
def _connect(self):
if self.db:
try:
self.db.close()
except:
pass
self.db = MySQLdb.connect(host = self.conf['host'], user = self.conf['user'], passwd = self.conf['passwd'], db = self.conf['db'], use_unicode = True, charset = 'utf8')
def cursor(self):
try:
self.db.ping()
return self.db.cursor()
except MySQLdb.OperationalError:
self._connect()
return self.db.cursor()