kvaje
kvaje

Reputation: 91

KNPPaginator - Invalid parameter number: number of bound variables does not match number of tokens (Symfony2, Doctrine)

I use KNPPaginatorBundle and I get this error message if I add a setParameter into a query.

I use Symfony 2.4.2, doctrine 2.2.3, knp-components 1.2.5 and KNP Paginator 2.4.0.

If I use:

$qb = $this->createQueryBuilder('c')
->addSelect('translation')
->leftJoin('c.translations', 'translation')
->where('c.lvl = 1');

it is working ok.

But if I use:

$qb = $this->createQueryBuilder('c')
->addSelect('translation')
->leftJoin('c.translations', 'translation')
->where('c.lvl = :lvl')
->setParameter('lvl', '1');

I got this error message

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

Is this my mistake or bug in bundle or Symfony? Thanks for your help.

Upvotes: 0

Views: 677

Answers (1)

dev_rybo
dev_rybo

Reputation: 11

You are getting this error because you are using the where clause. When using setParameter you need to use andWhere. it should look like the following:

$qb = $this->createQueryBuilder('c')
->addSelect('translation')
->leftJoin('c.translations', 'translation')
->andWhere('c.lvl = :lvl')
->setParameter('lvl', '1');

Upvotes: 1

Related Questions