在哪里与Doctrine 2 DBAL

时间:2014-03-22 17:46:55

标签: mysql doctrine dbal

如何在Doctrine DBAL中使用WHERE IN子句?

以下查询无效,它搜索名称"Bob","Elvis","Bill"(作为字符串):

$users = $dbc->fetchAssoc("SELECT * FROM users WHERE name IN(:users_names)", array(
    'users_names' => '"Bob","Elvis","Bill"'
));

我尝试使用数组,这是同样的问题。

1 个答案:

答案 0 :(得分:0)

试试这个:

 $searchParameters = array("Bob","Elvis","Bill");

    $users = "SELECT * FROM users WHERE name IN (?1)";
    $q = $em->createQuery($users)
       ->setParameter(1, $searchParameters);

    $result = $q->execute();