18 lines
620 B
Python
18 lines
620 B
Python
import pymysql
|
|
|
|
|
|
class MySQL:
|
|
def __init__(self, **kwargs):
|
|
self.hostname = kwargs["hostname"]
|
|
self.username = kwargs["username"]
|
|
self.password = kwargs["password"]
|
|
self.database = kwargs["database"]
|
|
|
|
def query(self, query, args=None):
|
|
conn = pymysql.connect(host=self.hostname, user=self.username, password=self.password, db=self.database,
|
|
charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
|
|
with conn.cursor() as cursor:
|
|
cursor.execute(query, args)
|
|
conn.commit()
|
|
return cursor.fetchall()
|