2023-09-20 20:30:31 -06:00
|
|
|
import pymysql
|
|
|
|
|
|
|
|
|
|
|
|
class DatabaseConnection:
|
2023-09-26 23:59:22 -06:00
|
|
|
host: str = None
|
|
|
|
username: str = None
|
|
|
|
password: str = None
|
2023-10-11 18:04:15 -06:00
|
|
|
database_name: str = None
|
2023-09-20 20:30:31 -06:00
|
|
|
|
2023-10-11 18:04:15 -06:00
|
|
|
def init_db(self, host, username, password, database_name):
|
2023-09-26 23:59:22 -06:00
|
|
|
self.host = host
|
|
|
|
self.username = username
|
|
|
|
self.password = password
|
2023-10-11 18:04:15 -06:00
|
|
|
self.database_name = database_name
|
2023-09-26 23:59:22 -06:00
|
|
|
|
|
|
|
def cursor(self):
|
|
|
|
db = pymysql.connect(
|
|
|
|
host=self.host,
|
|
|
|
user=self.username,
|
|
|
|
password=self.password,
|
2023-10-11 18:04:15 -06:00
|
|
|
database=self.database_name,
|
2023-09-23 19:08:30 -06:00
|
|
|
charset='utf8mb4',
|
2023-09-24 13:02:30 -06:00
|
|
|
autocommit=True,
|
2023-09-20 20:30:31 -06:00
|
|
|
)
|
2023-09-26 23:59:22 -06:00
|
|
|
return db.cursor()
|
2023-09-20 20:30:31 -06:00
|
|
|
|
|
|
|
|
2023-09-26 23:59:22 -06:00
|
|
|
database = DatabaseConnection()
|