注意:Doctrine查询中的数组到字符串转换
foreach($listLocations as $k=>$location){
$list[] = "'".$location['id']."'";
}
$storesList = implode(',', $list);
/打印字符串(23)“'191'、'195'、'215'、'265'”$storesList = (string)$storesList;
我把它改成了字符串,但在查询时它仍然认为是数组
$sql="SELECT * from tbl_students WHERE s.store_id IN (".$storesList .")";
$conn = $this->getEntityManager()->getConnection();
$stmt = $conn->prepare($sql);
最佳答案
首先将$list[] = "'".$location['id']."'";
更改为
$list[] = $location['id'];
现在请执行以下操作:
$storesList = "('".implode("','", $list)."')";
和
$sql="SELECT * from tbl_students WHERE s.store_id IN $storesList";
帮助链接示例:-https://eval.in/736486
关于php - 注意:Doctrine查询中的数组到字符串的转换,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42218606/