Python访问MySQL封装的常用类实例

2019-10-05 13:43:51王振洲

        self.conn.close()
        return returnData
     
    def update(self, sqlString):
        cursor=self.conn.cursor()
        cursor.execute(sqlString)
        self.conn.commit()
        cursor.close()
        self.conn.close()
 
if __name__=="__main__":
    db=DB('127.0.0.1',3306,'root','','wordpress')
    print db.query("show tables;")

使用方法为文件下面的main函数,使用query执行select语句并获取结果;或者使用update进行insert、delete等操作。

希望本文所述对大家的Python程序设计有所帮助。