22 lines
469 B
Python
22 lines
469 B
Python
from .secret import host, user, password, database
|
|
|
|
import pymysql.cursors
|
|
|
|
def get_db():
|
|
connection = pymysql.connect(
|
|
host=host,
|
|
user=user,
|
|
password=password,
|
|
database=database,
|
|
charset='utf8mb4',
|
|
cursorclass=pymysql.cursors.DictCursor
|
|
)
|
|
try:
|
|
yield connection
|
|
finally:
|
|
connection.close()
|
|
|
|
# cursor = connection.cursor()
|
|
# cursor.execute(sql, ())
|
|
# cursor.fetchall()
|
|
# connection.commit() |