1、通过pymysql连接数据库并进行数据库操作
2、查询数据
3、更新修改SQL方法封装
import pymysql.cursors import json class OperationMysql: def __init__(self): self.conn = pymysql.connect( host=‘127.0.0.1‘, port=3306, user=‘test‘, passwd=‘11111‘, db=‘test‘, charset=‘utf8‘, cursorclass=pymysql.cursors.DictCursor ) self.cur = self.conn.cursor() # 查询一条数据 def search_one(self, sql): self.cur.execute(sql) result = self.cur.fetchone() return result # 更新SQL def updata_one(self, sql): self.cur.execute(sql) self.conn.commit() self.conn.close() if __name__ == ‘__main__‘: op_mysql = OperationMysql() res = op_mysql.search_one("SELECT * from order WHERE order_no=‘M191023401681654‘") print(res)
原文地址:https://www.cnblogs.com/CesareZhang/p/12062329.html
时间: 2024-10-10 04:33:21