class sqlHandler(): def __init__(self): self.connect() def connect(self): self.conn = conn = pymysql.connect(host="127.0.0.1", port=3306, user="root", passwd="", db="db2") self.cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) def getOne(self,sql,args): self.cursor.execute(sql, args) result = self.cursor.fetchone() return result def getAll(self,sql,args): self.cursor.execute(sql, args) result = self.cursor.fetchall() return result def modify(self,sql,args): self.cursor.execute(sql,args) self.conn.commit() def modifyMany(self,sql,args): self.cursor.executemany(sql,args) self.conn.commit() def close(self): self.cursor.close() self.conn.close() def create(self,sql,args): self.cursor.execute(sql,args) ret = self.cursor.lastrowid self.conn.commit() return ret