tuxbot-bot/cogs/utils/db.py

30 lines
968 B
Python
Raw Normal View History

2018-12-03 01:26:23 +01:00
import pymysql
2019-05-30 00:59:20 +02:00
2018-12-03 01:26:23 +01:00
def connect_to_db(self):
2019-05-30 00:59:20 +02:00
mysqlHost = self.bot.config.mysql["host"]
mysqlUser = self.bot.config.mysql["username"]
mysqlPass = self.bot.config.mysql["password"]
mysqlDB = self.bot.config.mysql["dbname"]
try:
return pymysql.connect(host=mysqlHost, user=mysqlUser,
passwd=mysqlPass, db=mysqlDB, charset='utf8')
except KeyError:
print(
"Rest in peperoni, Impossible de se connecter a la base de données.")
print(str(KeyError))
return
2018-12-03 01:26:23 +01:00
def reconnect_to_db(self):
2019-05-30 00:59:20 +02:00
if not self.conn:
mysqlHost = self.bot.config.mysql["host"]
mysqlUser = self.bot.config.mysql["username"]
mysqlPass = self.bot.config.mysql["password"]
mysqlDB = self.bot.config.mysql["dbname"]
2018-12-03 01:26:23 +01:00
2019-05-30 00:59:20 +02:00
return pymysql.connect(host=mysqlHost, user=mysqlUser,
passwd=mysqlPass, db=mysqlDB, charset='utf8')
return self.conn