Exemplo n.º 1
0
 def __init__(self):
     """初始化方法中,连接到数据库"""
     self.con = pymysql.connect(host=conf.get("mysql", "host"),
                                port=conf.getint("mysql", "port"),
                                user=conf.get("mysql", "user"),
                                password=conf.get("mysql", "password"),
                                charset="utf8",
                                cursorclass=pymysql.cursors.DictCursor)
     # 创建一个游标对象
     self.cur = self.con.cursor()
Exemplo n.º 2
0
 def __init__(self):
     # 连接数据库,创建游标。
     # 1、建立连接
     self.conn = pymysql.connect(host=conf.get("mysql", "host"),
                                 port=conf.getint("mysql", "port"),
                                 user=conf.get("mysql", "user"),
                                 password=conf.get("mysql", "password"),
                                 database=conf.get("mysql", "database"),
                                 charset="utf8",
                                 cursorclass=pymysql.cursors.DictCursor)
     # 2、创建游标
     self.cur = self.conn.cursor()