时间:2021-07-01 10:21:17 帮助过:46人阅读
 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();}   
  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,可以满足条件