版权声明:学习交流为主,未经博主同意禁止转载,禁止用于商用。 https://blog.csdn.net/u012965373/article/details/88566465
# -*- coding:utf-8 -*-
__author__ = 'yangxin'
import pymysql
class MysqlClient(object):
def __init__(self, host, port, user, passwd, db):
self.coon = pymysql.connect(host=host, port=port, user=user, passwd=passwd, db=db, charset='utf8')
def query_sql(self, sql):
cur = self.coon.cursor() # 建立游标
cur.execute(sql) # 查询数据
res = cur.fetchall() # 获取结果
cur.close() # 关闭游标
return res
def close(self):
self.coon.close()