php - Doctrine multiple where 条件

标签 php zend-framework doctrine-orm

我正在使用 Doctrine 2.3,我在为以下场景设计查询时遇到困难。

SELECT * FROM source WHERE source_id ='10' or source_id ='100' or source_id ='30'

我这样做是为了选择单个 ID,但我不确定该怎么做。

$qry = $this->manager()->create()
        ->select('e')
        ->from($this->entity, 'e')
        ->where('e.id = :id');

有人可以帮助我吗? 如果我了解上述查询的工作原理,我将解决其他问题。 如下。

 SELECT * FROM source WHERE source_id ='10' and source_name ='test' and source_val ='30'

最佳答案

对于第一个改变你的 where 子句,比如,

->where('e.id IN (:ids)') 
->setParameter('ids', $ids)

哪里 $ids = array('10','100','');

要为您的第二个查询使用和条件,它应该类似于,

$qry = $this->manager()->create()
       ->select('e')
       ->from($this->entity, 'e')
       ->where('e.source_id = :id')
       ->andWhere('source_name=?', 'test')
       ->andWhere('source_val=?', '30')

关于php - Doctrine multiple where 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16910849/

相关文章:

php - 如何在 php 中显示 TreeView ?

php - 使用 Behat 3 和 Mink 1.5 的页面对象扩展引发异常

php - 在 .htaccess 或我的 PHP 代码中强制使用 SSL,导致重定向循环错误

postgresql - 一个数据库中的多个 Symfony 项目,但不同的 Postgres 模式

symfony - 同一实体如何实现 Doctrine 中的父子关系?

PHP MYSQL 查询组合并添加两个相等的结果

php - JQuery 日期选择器在 ajax 调用后不工作

php - 如何从 Zend 只返回 JSON

zend-framework - 在 Zend 框架中设置自定义错误级别

Symfony Doctrine 数据类型仅适用于 findBy 不适用于 querybuilder