[python] pymysql格式化字符串安全操作

  • sql语句的参数化,可以有效防止sql注入
  • 全部使用%s占位
# 执行select语句,并返回受影响的行数:查询所有数据
count = cs1.execute('select * from goods where name=%s', params)
# 注意:
# 如果要是有多个参数,需要进行参数化
# 那么params = [数值1, 数值2....],此时sql语句中有多个%s即可,例:
UPDATE user set name=%s where id=%s", [new_name, edit_id,])
posted @ 2019-09-09 12:17  Moke丶青  阅读(1305)  评论(0编辑  收藏  举报