TSEWebChecker/Python/dbUtils.py

22 lines
783 B
Python
Raw Normal View History

2023-03-22 14:59:59 +08:00
# author: Xunhui Zhang
# date: 2020-09-13
# object: function used to connect to mysql database
import pymysql
def connectMysqlDB(config, autocommit = True):
db = pymysql.connect(host=config['mysql']['host'],
port=int(config['mysql']['port']),
user=config['mysql']['user'],
password=config['mysql']['passwd'],
db=config['mysql']['db'],
local_infile=1,
use_unicode=True,
charset='utf8mb4',
sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION',
autocommit=autocommit)
return db