我正在使用 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/