开发者

Doctrine2 Query builder problem with like

I'm using this for in my doctrine2 query but it won't work

  $obj_query_builder->select('p')
   ->from('General\Domain\Product', 'p')
   ->where('p.cach_all_stop_words LIKE ?', '%avond%');

It must be this query:

SELECT * FROM `product` WHERE `cach_all_stop_words开发者_开发问答` LIKE '%avond%'

But there is an error in my query I think


The QueryBuilder syntax in Doctrine 2 which is defined in http://www.doctrine-project.org/docs/orm/2.0/en/reference/query-builder.html is slightly different than the one you used in your query.

Can you try this query:

$obj_query_builder->add('select', 'p')
  ->add('from', 'General\Domain\Product p')
  ->add('where', 'p.cach_all_stop_words LIKE ?1')
  ->setParameter(1, '%avond%')

You can also see some other examples in the link I posted above.

EDIT: I saw below in the page in "Helper methods" that your syntax should also work. Try the query I wrote above.


$qb = $this->getEntityManager()->createQueryBuilder();
$qb -> select('p')
    ->from('General\Domain\Product' , 'p')
    ->where($qb->expr()->like('p.cach_all_stop_words', $qb->expr()->literal('%avond%')));

$query = $qb->getQuery();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜