1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
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')
|