#生成预处理对象
$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的数据查询不到!
在传递这些多个值的时候或者多条件的时候应该怎样写;Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
拼接sql语句就好了
TP5.1.21 版本之后数组查询支持:
要达到这样子查询:
1、首先引用: use think\db\Where;
2、定义数组:$where = new Where;
3、就可以用了:$where['title'] = ['like', "%".$sotitle."%"];
参考址:https://blog.csdn.net/haibo0668/article/details/78295485