pymsyql操作mysql

这种类一般是读取小标或则业务类型的数据处理时使用,现在一般是批量操作
class Pymysql_Do:
def __init__(self, db,ip='localhost',port=3306,Users='root',PassWd='root',CharSet='utf8'):
self.db = db
self.ip = ip
self.port = port
self.Users = Users
self.PassWd = PassWd
self.CharSet = CharSet
self.db = pymysql.connect(host=self.ip, port=self.port, user=self.Users, passwd=self.PassWd, db= self.db, charset=self.CharSet )

def Mysql_Read(self, sql):
cursor = self.db.cursor()
cursor.execute(sql)
rows = cursor.fetchall()
self.db.close()
return rows

def Mysql_Write(self, sql):
cursor = self.db.cursor()
cursor.execute(sql)
self.db.commit()
cursor.close()
self.db.close()
posted @ 2021-03-29 11:21  星辰大海-sdifens  阅读(61)  评论(0编辑  收藏  举报