Python通过pymysql连接数据库并进行查询和更新SQL方法封装
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)
相关推荐
lbyd0 2020-11-17
sushuanglei 2020-11-12
腾讯soso团队 2020-11-06
gaobudong 2020-11-04
yangkang 2020-11-09
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31
dingyahui 2020-10-30