mysql注入问题

import pymysql


conn = pymysql.connect(
host = '127.0.0.1',
port = 3306,
user = 'root',
password = '123',
database = 'day38',
charset = 'utf8', # 编码千万不要加- 如果写成了utf-8会直接报错
autocommit = True # 这个参数配置完成后 增删改操作都不需要在手动加conn.commit了
)
cursor = conn.cursor(pymysql.cursors.DictCursor) # 产生一个游标对象 以字典的形式返回查询出来的数据 键是表的字段 值是表的字段对应的信息

 

# sql = 'insert into user(name,password) values("jerry","666")'
# sql = 'update user set name = "jasonhs" where id = 1'
sql = 'delete from user where id = 6'
cursor.execute(sql)


"""
增删改操作 都必须加一句
conn.commit()操作
"""
# conn.commit()
# username = input('username>>>:')
# password = input('password>>>:')
# sql = "select * from user where name =%s and password = %s"
# print(sql)
# res = cursor.execute(sql,(username,password)) # 能够帮你自动过滤特殊符号 避免sql注入的问题
# # execute 能够自动识别sql语句中的%s 帮你做替换
# if res:
# print(cursor.fetchall())
# else:
# print('用户名或密码错误')


"""
sql注入 就是利用注释等具有特殊意义的符号 来完成一些骚操作

后续写sql语句 不要手动拼接关键性的数据
而是让excute帮你去做拼接

 


"""

转载于:https://www.cnblogs.com/wkq0220/p/11397478.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值