问题:如果直接插入一条某字段为 % ,会报错。

# -*- coding: utf-8 -*-
import pymysql.cursors
connect = pymysql.Connect(
    host='**********',
    port=3306,
    user='root',
    passwd='123456',
    db='ry',
    charset='utf8'
)
 
def judge():
    cursor = connect.cursor()
    sql ="INSERT INTO test_log(rwmc, scenario) VALUES ('%%', '%s');"
    data = 'bb'
    cursor.execute(sql % data)
    connect.commit()
    print('成功插入', cursor.rowcount, '条数据')
 
 
if __name__ == '__main__':
    judge()

 

posted @ 2021-07-19 09:50  御世制人  阅读(144)  评论(0)    收藏  举报