开发者

Where Method not working in Doctrine Query Builder?

I have the ff basic query. The query works fine without WHERE method being called.

$qb->select(array('m', 'c'))
           ->from('models\Book', 'm')
           ->leftJoin('m.Chapters', 'c')
           ->where('m.Slug=?', $slug)
           ->orderBy('c.CreateDate', 'DESC');

But after I call it with WHERE method in Doctrine. The ff. "hard to understand error" appear:

开发者_如何学JAVA
Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'Invalid parameter format, ? given, but :<name> or ?<num> expected.' 

What could be the solution for this problem?


I think the message is self-explanatory.

With Doctrine2, you can use either:

    $qb->where('m.Slug=:slug')
       ->setParameter('slug', $slug);

either:

    $qb->where('m.Slug=?1')
       ->setParameter(1, $slug);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜