Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8838591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:02:21+00:00 2026-06-14T10:02:21+00:00

I have an array of terms that I would like to match using the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:02:23+00:00Added an answer on June 14, 2026 at 10:02 am

    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:

    // Query Builder added to show difference in code readability I personally use queryBuilder mostly
    $query = $this->getDoctrine()->getManager()->createQueryBuilder();
    $query->select('p')
            ->from('Post', 'p')
            ->orderBy('p.datetime', 'DESC');
    $i = 0;
    $parameters = array();
    foreach ($textterms as $key => $text)
    {
        $query->orWhere('p.searchfield LIKE ?' . $i++);
        $parameters[] = '%-' . $text . '-%';
    }
    $query->setParameters($parameters);
    $posts = $query->getQuery()->getResult();
    
    // Query
    $orX = new \Doctrine\ORM\Query\Expr\Orx();
    $i = 0;
    $parameters = array();
    foreach ($textterms as $text)
    {
        $orX->add('p.searchfield LIKE ?' . $i++);
        $parameters[] = '%-' . $text . '-%';
    }
    $orX = (string)$orX;
    if(!empty($orX))
    {
        $orX = 'WHERE ' . $orX;
    }
    $sql = sprintf('SELECT p FROM Post p %s ORDER BY p.datetime DESC', $orX);
    $query = $this->getDoctrine()->getManager()->createQuery($sql);
    $query->setParameters($parameters);
    $posts = $query->getResult();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a static char array member initialized in terms of
I have a search form that would like the users to search multiple terms.
I have a masked array that I would like to add to another array
I have a list of regular expressions and I would like to match with
I have a table of dictionary terms and now I would like to create
Using the JQuery autocomplete I have a function that produces an Array of friends
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I Have a search bar that searches an array, and updates a UITableView with
I have an application that searches a database of addresses. The page visitor enters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.