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:
开发者_如何学JAVAUncaught 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);
精彩评论