If the condition requires the use of IN, how should I write it? Could you please give me an example?
Wei
Wei 2018-11-14 10:16:29
0
3
1499
#生成预处理对象
$sql = 'SELECT * FROM dede_archives WhERE id IN (:id)' ;
$stmt = $pdo -> prepare($sql);
 
 
#参数的绑定并执行
$id = implode(',',[2,3,4,5,6,7,8,9]);
 
#$stmt -> bindParam(':id',$id,PDO::PARAM_STR);
$stmt -> bindValue(':id','2,3,4,5,6,7,8,9',PDO::PARAM_STR);
$stmt -> execute();
 
结果只能查询到id为2的数据,其他id的数据查询不到! 
在传递这些多个值的时候或者多条件的时候应该怎样写;


Wei
Wei

reply all(2)
Summer

Just splice sql statements

phpcn_u3030

TP5.1.21 After version, array query support:

To achieve this subquery:

1. First quote: use think\db\Where;

2. Define the array: $where = new Where;

3. You can use it: $where['title'] = ['like', "%".$sotitle."%"];

Reference address: https://blog.csdn.net/haibo0668/article/details/78295485

  • reply Well, yours is encapsulated in TP. How can I check if the native PHP should be changed?
    Wei author 2018-11-14 10:57:03
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template