0

I try to get multiple values from setParameters, but with the same 'key', litke this :

->where('d.type = :type')->setParameters(array('type'=> 7, 'type => '8'))

But i have only result from '8', and not 7 + 8.

5
  • Keys must be unique Commented Mar 30, 2017 at 7:25
  • so i can't get multiple values from type ? With an other method ? Commented Mar 30, 2017 at 7:25
  • Do want get as Select * From YourTable as d where d.type IN (7,8)? Commented Mar 30, 2017 at 7:41
  • That's not a Symfony question, its a SQL question. You must use IN clausule from MySQL. Commented Mar 30, 2017 at 8:08
  • Thanks, i have updated my title, and that was indeed 'IN' :) Commented Mar 30, 2017 at 8:12

1 Answer 1

2

Change your where condition as follows

->where('d.type IN (:types)')
->setParameter('types', array(7, 8))

or

$qb = $this->createQueryBuilder('d');

// other parts of your query using $qb variable

->where($qb->expr()->in('d.type', array(7, 8));

With first example, if array(7, 8) is a parameter variable (passed to function) and it's empty, no error will be raised.

In second, if array(7, 8) is a parameter variable (passed to function) and it's empty, an error will be raised (so you should check carefully before run the query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.