UI自动化web端框架mymysql.py代码

import pymysql
from lib.core.config import Config,ConfigType
class MyMysql(object):
def __init__(self):
self.config = Config()
self.data = self.config.read(ConfigType.MYSQL)
self.db = pymysql.connect(**self.data)
self.cur = self.db.cursor(cursor = pymysql.cursors.DictCursor)

def select_sql(self,sql):
try:
self.cur.execute(sql)
except Exception as e:
print('这里出错了,错误信息是:%s' % e)
else:
return self.cur.fetchone()

def other_sql(self,sql):
try:
self.cur.execute(sql)
except Exception as e:
print('这里出错了,错误信息是:%s' % e)
else:
self.db.commit()

def close(self):
self.cur.close()
self.db.close()

if __name__ == '__main__':
print(MyMysql().select_sql('select * from user_info;'))

猜你喜欢

转载自www.cnblogs.com/laosun0204/p/9267999.html