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

  • SEARCH
  • Home
  • 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 9173889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:39:36+00:00 2026-06-17T16:39:36+00:00

Can anyone enlighten me as to why this query isn’t working please? I tried

  • 0

Can anyone enlighten me as to why this query isn’t working please? I tried alternating between single and double quotes as well.

$em = $this->getDoctrine()->getManager();

$query = $em->createQuery('SELECT t FROM AcmeBlogBundle:BlogTag t WHERE t.title LIKE \'%:title%\'')
->setParameter('title', $keyword);

Doctrine simply returns Invalid parameter number: number of bound variables does not match number of tokens.

Also, is it better to perform such a query using the createQuery method or createQueryBuilder?

  • 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-17T16:39:37+00:00Added an answer on June 17, 2026 at 4:39 pm

    PDO treats both the keyword and the % wildcards as a single token. You cannot add the wildcards next to the placeholder. You must append them to the string when you bind the params.

    Also see this comment on the php docs.

    Therefore you will need to do the following:

    $qb = $em->createQueryBuilder();
    
    $qb
        ->select('tag')
        ->from('AcmeBlogBundle:BlogTag', 'tag')
        ->where($qb->expr()->like('tag.title', ':title'))
        ->setParameter('title', '%' . $keyword . '%')
    ;
    

    or

    $query = $em->createQuery('SELECT t FROM AcmeBlogBundle:BlogTag t WHERE t.title LIKE :title');
    $query->setParameter('title', '%' . $keyword . '%');
    

    I prefer to use the query builder because it is nicer for structuring and making your statement more maintainable

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me why this code would not be working? $('body').on('test', function() {
Can anyone enlighten me as to why i'm getting an EXC_BAD_ACCESS on this chunk
Can anyone enlighten me as to why this bit of code spits back that
Can anyone enlighten me, what is the difference between hasOwnProperty and propertyIsEnumerable : function
Can anyone enlighten me to a way I can Highlight the content of an
Can anyone enlighten me as to why the following code won't work in IE7
Can anyone enlighten me why the following won't work? $ groups staff btgroup $
Can anyone enlighten me in what scenarios I would get the following error in
Can anyone explain to me why this program: for(float i = -1; i <
Can anyone help - this is driving me mad. I am calling a mysql

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.