Python 操作MySql数据库

来源:互联网 发布:冲田杏梨seo 681 编辑:程序博客网 时间:2024/06/04 22:19
# -*- coding: utf-8 -*-import sysreload(sys)import  MySQLdbsys.setdefaultencoding('utf-8')class MySqlBase:    def __init__(self):        self.myCon=MySQLdb.connect(host="*******",                              user="*******",passwd="*******",                              db='*******',port=*******)        self.myCon.set_character_set('utf8mb4')        self.cur=self.myCon.cursor()    def openDB(self):        self.myCon=MySQLdb.connect(host="*******",                              user="*******",passwd="*******",                              db='*******',port=*******)        self.myCon.set_character_set('utf8mb4')        self.cur=self.myCon.cursor()    def openCur(self):        self.cur.close()        self.cur=self.myCon.cursor()    def iCommit(self):        self.openCur()        self.myCon.commit()    def closeDB(self):        self.cur.close()        self.myCon.close()
0 0