I have an array of terms that I would like to match using the LIKE wildcard in one Doctrine 2 query. The database is SQL and I’m using DQL but a query builder solution would be fine.
My current query setup is this:
foreach($textterms as $text)
{
$parameters[] = '%-'.$text.'-%';
}
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT p FROM Post p WHERE p.searchfield IN LIKE (:text) ORDER BY p.datetime DESC'
)->setParameter('text', $parameters);
$posts = $query->getResult();
But I get the symfony error
“QueryException: [Syntax Error] line 0, col 62: Error: Expected Literal, got ‘(‘”
Is this query possible in doctrine?
You’re receiving such error because query is expecting a value after LIKE statement. There is no such a thing like “IN LIKE”. Possible solutions which I would consider: