【问题标题】:Notice: Array to String Converstion in Doctrain Query注意:Doctrine Query 中的数组到字符串的转换
【发布时间】:2017-02-14 05:34:21
【问题描述】:

注意:Doctrine Query 中数组到字符串的转换

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);

【问题讨论】:

    标签: php arrays string symfony doctrine-orm


    【解决方案1】:

    a) 首先改变:

    $list[] = "'".$location['id']."'";
    

    $list[] = $location['id'];
    

    b) 现在执行如下操作:-

    $storesList = "('".implode("','", $list)."')";
    

    c) 和

    $sql="SELECT * from tbl_students WHERE s.store_id IN $storesList";
    

    帮助示例链接:-https://eval.in/736486

    【讨论】:

    • 不错且快速的答案。很好的例子。
    • 感谢您的回答,但我仍然遇到同样的问题。
    • 感谢它因为其他一些问题,我已修复它感谢您的帮助。
    • @Developer 很高兴为您提供帮助:):)
    猜你喜欢
    • 2023-03-06
    • 2013-11-03
    • 2017-08-11
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多