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;'))
posted @ 2018-07-05 14:06  laosun0204  阅读(155)  评论(0编辑  收藏  举报