标签:turn self 三方 pre 修改 绑定 charset mysql安装 chart
import pymysql # 连接mysql的三方库,可以pip3 install pymysql安装
def exc1(host, port, db, charset, sql):
conn = pymysql.connect(host, port, db, charset)
conn.execute(sql)
return xxx
def exc2(proc_name):
conn = pymysql.connect(host, port, db, charsett)
conn.call_proc(sql)
return xxx
exc1('1.1.1.1', 3306, 'db1', 'utf-8', 'select * from t1')
exc1('1.1.1.1', 3306, 'db1', 'utf-8', 'select * from t2')
exc1('1.1.1.1', 3306, 'db1', 'utf-8', 'select * from t3')
exc1('1.1.1.1', 3306, 'db1', 'utf-8', 'select * from t4')
def exc1(sql, host='1.1.1.1', port=3306, db='db1', charset='utf-8'):
conn = pymysql.connect(host, port, db, charset)
conn.execute(sql)
return xxx
exc1('select * from t1')
exc1('select * from t2')
exc1('select * from t3')
exc1('select * from t4')
import pymysql
class Foo:
def __init__(self, host, port, db, chartset):
self.host = host
self.port = port
self.db = db
self.charset = chartset
def exc1(self, sql):
conn = pymysql.connect(self.host, self.port, self.db, self.charset)
conn.execute(sql)
return xxx
def exc2(self, proc_name):
conn = pymysql.connect(self.host, self.port, self.db, self.charsett)
conn.call_proc(sql)
return xxx
obj1 = Foo('1.1.1.1', 3306, 'db1', 'utf-8')
obj1.exc1('select * from t1')
obj1.exc1('select * from t2')
obj1.exc1('select * from t3')
obj1.exc1('select * from t4')
obj2 = Foo('1.1.1.2', 3306, 'db1', 'utf-8')
obj2.exc1('select * from t4')
标签:turn self 三方 pre 修改 绑定 charset mysql安装 chart
原文地址:https://www.cnblogs.com/nickchen121/p/10987699.html