简体   繁体   中英

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:

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);

La solucion es:

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

el espacio entre el = y:, osea: m.Slug=:slug ok, m.Slug=:slug bad

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM