27 lines
692 B
Python
27 lines
692 B
Python
|
|
"""
|
||
|
|
@project:DataBaseTableController
|
||
|
|
@File:DataBaseConnect.py
|
||
|
|
@IDE:PyCharm
|
||
|
|
@Author:徐彬程
|
||
|
|
@Date:2024/1/30 13:05
|
||
|
|
"""
|
||
|
|
from pymysql import OperationalError, ProgrammingError
|
||
|
|
import pymysql
|
||
|
|
|
||
|
|
|
||
|
|
class DataBaseConnectClass:
|
||
|
|
@classmethod
|
||
|
|
def connect_to_database(cls, request):
|
||
|
|
try:
|
||
|
|
connection = pymysql.connect(
|
||
|
|
host=request.data['host'],
|
||
|
|
user=request.data['user'],
|
||
|
|
password=request.data['password'],
|
||
|
|
charset='utf8mb4',
|
||
|
|
cursorclass=pymysql.cursors.DictCursor
|
||
|
|
)
|
||
|
|
return connection
|
||
|
|
# TODO 错误返回
|
||
|
|
except OperationalError as e:
|
||
|
|
return e
|