Php 多向条件原则
我正在使用条令2.3,我面临着为以下场景设计查询的困难Php 多向条件原则,php,zend-framework,doctrine-orm,Php,Zend Framework,Doctrine Orm,我正在使用条令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') -&
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')
输出
从TblName中选择e,其中e.id=$eid和source_id=$source_id和field=$value和id在(1,2,3)和(id=$id和name=$name)就像@Rikesh说在
表达式中使用,但这里有另一种连接和
表达式的好方法
->where('e.foo = :foo', 'e.bar = :bar')
->setParameters([
'foo' => $foo,
'bar' => $bar,
])
输出
。。。其中(e.foo=“foo”和e.bar=“bar”)…
我会尝试,当我工作时,我会接受你的答案。。谢谢你的答复@Rikeshc你能在这方面帮助我吗?@ToleaBivol它是andWhere(),据我所知,symfony 2.3-symfony 4中不存在名为addWhere()的函数。@ahmed Abumostafa。
->where('e.foo = :foo', 'e.bar = :bar')
->setParameters([
'foo' => $foo,
'bar' => $bar,
])