注意:Doctrain Query中的数组到字符串对话

时间:2017-02-14 05:34:21

标签: php arrays string symfony doctrine-orm

  

注意: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);

1 个答案:

答案 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