I have an array of fields I possibly want to look for in my DB:
$locations = array(
2,3,5
);
The number of locations can differ, and I want to create a prepared statement (with Doctrine in Symfony2) that does the same as this:
SELECT * FROM locations WHERE start = 1 AND (end = 2 OR end = 3 OR end = 5)
(I think) I know how to use prepared statements in general, like this:
$query = $em->createQuery(
'SELECT l
FROM AppBundle:Location l
WHERE l.start > :start
AND (l.end = :end1
OR l.end = :end2
OR l.end = :end3)
ORDER BY l.duration ASC'
)
->setParameter('start', '1')
->setParameter('end1', '2')
->setParameter('end2', '3')
->setParameter('end3', '5');
but how can I do that dynamically if I do not have the size of the array?
Any hint appreciated!