<?phptry { $db = new pdo("mysql:host=localhost;dbname=mtest;charset=utf8", 'root', 'root'); $db -> 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'].'<br><br>'; } $db = null;} catch(pdoexception $e) { echo $e -> getmessage();}
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 恒为假,表达式不会成立,自然也就找不到
实际执行的是
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,可以满足条件
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号