输入的参数永远当作字串类型引用。
简单例子:
错误
SELECT id, name FROM product WHERE id = %para%
正确
SELECT id, name FROM product WHERE id = '%para%'
正常情况下%para%是一个整数,比如101,实际query是
SELECT id, name FROM product WHERE id = '101'
没有问题。
恶意攻击情况下,%para%可能是一个SQL命令,比方0 DELETE TABLE product
错误方法下,query成为
SELECT id, name FROM product WHERE id = 0 DELETE TABLE product
正确方法下,query成为
SELECT id, name FROM product WHERE id = '0 DELETE TABLE product'
Query出错,不会被执行。
简单例子:
错误
SELECT id, name FROM product WHERE id = %para%
正确
SELECT id, name FROM product WHERE id = '%para%'
正常情况下%para%是一个整数,比如101,实际query是
SELECT id, name FROM product WHERE id = '101'
没有问题。
恶意攻击情况下,%para%可能是一个SQL命令,比方0 DELETE TABLE product
错误方法下,query成为
SELECT id, name FROM product WHERE id = 0 DELETE TABLE product
正确方法下,query成为
SELECT id, name FROM product WHERE id = '0 DELETE TABLE product'
Query出错,不会被执行。