注意:Doctrine查询中的数组到字符串转换
foreach($listLocations as $k=>$location){
$list[] = "'".$location['id']."'";
}
$storesList = implode(',', $list);
//打印字符串(23)“'191','195','215','265'”
$storesList = (string)$storesList;
我将其更改为String,但在Query中仍将其视为数组
$sql="SELECT * from tbl_students WHERE s.store_id IN (".$storesList .")";
$conn = $this->getEntityManager()->getConnection();
$stmt = $conn->prepare($sql);
答案 0 :(得分:3)
首先将$list[] = "'".$location['id']."'";
更改为
$list[] = $location['id'];
现在如下所示: -
$storesList = "('".implode("','", $list)."')";
和
$sql="SELECT * from tbl_students WHERE s.store_id IN $storesList";
帮助的示例链接: - https://eval.in/736486