The doctrine is multiple, where the condition

I am working with Doctrine 2.3. I find it difficult to construct a query for the scenario below.

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

I did this to select a single identifier, but I'm not sure how to do it.

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

Can someone help me with this? If I get information about working on the above request, I will solve my other problems. Properly.

  SELECT * FROM source WHERE source_id ='10' and source_name ='test' and source_val ='30' 
+6
source share
3 answers

For the first, change the where where clause,

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

Where $ids = array('10','100','');

And for the use and conditions for the second request, it should be something like

 $qry = $this->manager()->create() ->select('e') ->from($this->entity, 'e') ->where('e.source_id = :id') ->andWhere('source_name=?', 'test') ->andWhere('source_val=?', '30') 
+9
source
 <?php $qry = $this->manager()->create() ->select('e') ->from($this->entity, 'e') ->where('e.id = ?', $eid) ->addWhere('source_id = ?', $source_id) ->addWhere('field = ?', $value) ->addWhereIn('id', array(1,2,3)) ->addWhere('id = ? AND name = ?', array($id, $name)); ?> 

audio output

SELECT e FROM TblName WHERE e.id = $ eid AND source_id = $ source_id AND field = $ value AND id IN (1,2,3) AND (id = $ id AND name = $ Name)

+3
source

Like @Rikesh, use an IN expression, but here is another good way to concatenate AND expressions

 ->where('e.foo = :foo', 'e.bar = :bar') ->setParameters([ 'foo' => $foo, 'bar' => $bar, ]) 

audio output

... WHERE (e.foo = "foo" AND e.bar = "bar") ...

+1
source

Source: https://habr.com/ru/post/946470/


All Articles