您好,欢迎访问一九零五行业门户网

这段代码为什么能查询出_id = 1001的用户信息?

setattribute(pdo::attr_emulate_prepares, false); $stmt = $db -> prepare(select * from zhuru where _id=:usid ); $usid = '1001 and 1=0'; $stmt->bindparam(':usid',$usid,pdo::param_int); $exer = $stmt -> execute(); while ($rows = $stmt -> fetch(pdo::fetch_assoc)) { echo $rows['username'].'------' . $rows['nickname'].'
'; } $db = null;} catch(pdoexception $e) { echo $e -> getmessage();}
这段代码为什么能查询出_id = 1001的用户信息?
回复讨论(解决方案) select * from zhuru where _id=:usid 
实际执行的是
select * from zhuru where _id='1001 and 1=0'
不可能满足条件
退一步说,即便不给你加上单引号,执行的也是
select * from zhuru where _id=1001 and 1=0
1=0 恒为假,表达式不会成立,自然也就找不到
问题是查询到了_id=1001的用户的信息。
select * from zhuru where _id=:usid 
实际执行的是
select * from zhuru where _id='1001 and 1=0'
不可能满足条件
退一步说,即便不给你加上单引号,执行的也是
select * from zhuru where _id=1001 and 1=0
1=0 恒为假,表达式不会成立,自然也就找不到
执行的时候查询到了_id=1001的用户的信息。 实际执行的是
select * from zhuru where _id='1001 and 1=0'
因为 _id 是 int 类型,'1001 and 1=0' 转换为数值是 1001,可以满足条件
实际执行的是
select * from zhuru where _id='1001 and 1=0'
因为 _id 是 int 类型,'1001 and 1=0' 转换为数值是 1001,可以满足条件
怎么解决这个问题?
$db -> prepare(select * from zhuru where _id=:usid );
:usid加单引号会什么都查不到,即使$usid=1001;
其它类似信息

推荐信息