Esempio n. 1
0
 def __init__(self):
     config = ConfigLoader()
     host = config.get('mysql', 'host')
     port = config.getint('mysql', 'port')  # port 是一个数值
     user = config.get('mysql', 'usr')
     password = config.get('mysql', 'pwd')
     # 异常处理
     self.mysql = pymysql.connect(host=host,
                                  user=user,
                                  password=password,
                                  port=port,
                                  cursorclass=pymysql.cursors.DictCursor)
Esempio n. 2
0
 def __init__(self):
     config = ConfigLoader()
     host = config.get('mysql', 'host')
     port = config.getint('mysql', 'port')
     user = config.get('mysql', 'usr')
     password = config.get('mysql', 'pwd')
     #自行添加异常处理
     try:
         self.mysql = pymysql.connect(
             host=host,
             user=user,
             password=password,
             port=port,
             cursorclass=pymysql.cursors.DictCursor)  #建立连接
         print('数据库连接成功!')
     except AssertionError as e:
         print('数据库连接失败!', e)
         raise e