DDC-664: Not finding correct number of token parameters when using query builder #817

Closed
opened 2026-01-22 12:51:32 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 1, 2010).

Jira issue originally created by user mackstar:

The following code

$qb = $em->createQueryBuilder();
$qb->add('select', 's')
->add('from', 'Entities\Sessions s')
->add('where', 's.sessionid = ?1')
->add('andWhere', 's.lasttime > ?2')
->setParameter(1, $sessionid)
->setParameter(2, date('Y-m-d H:i;s'));
$session = $qb->getQuery()->execute();

Gives me the following error

Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'Invalid parameter number: number of bound variables does not match number of tokens' in /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/Query/QueryException.php:57
Stack trace:
#0 /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/Query.php(229): Doctrine\ORM\Query\QueryException::invalidParameterNumber()
#1 /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/AbstractQuery.php(522): Doctrine\ORM\Query->_doExecute()
#2 /Users/richardbspex/Sites/b-spex.com/common/login.php(54): Doctrine\ORM\AbstractQuery->execute()
#3 /Users/richardbspex/Sites/b-spex.com/dir/header.php(45): require_once('/Users/richardb...')
#4 /Users/richardbspex/Sites/b-spex.com/index.php(5): require_once('/Users/richardb...')
#5 {main}

thrown in /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/Query/QueryException.php on line 57

This is also the case if I use setParameters() or if I use tokens such as :sessionid, this works correctly when using just where but having the parameter in andWhere causes me problems. This could well be a bug.

Originally created by @doctrinebot on GitHub (Jul 1, 2010). Jira issue originally created by user mackstar: The following code $qb = $em->createQueryBuilder(); $qb->add('select', 's') ->add('from', 'Entities\Sessions s') ->add('where', 's.sessionid = ?1') ->add('andWhere', 's.lasttime > ?2') ->setParameter(1, $sessionid) ->setParameter(2, date('Y-m-d H:i;s')); $session = $qb->getQuery()->execute(); Gives me the following error Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'Invalid parameter number: number of bound variables does not match number of tokens' in /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/Query/QueryException.php:57 Stack trace: #0 /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/Query.php(229): Doctrine\ORM\Query\QueryException::invalidParameterNumber() #1 /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/AbstractQuery.php(522): Doctrine\ORM\Query->_doExecute() #2 /Users/richardbspex/Sites/b-spex.com/common/login.php(54): Doctrine\ORM\AbstractQuery->execute() #3 /Users/richardbspex/Sites/b-spex.com/dir/header.php(45): require_once('/Users/richardb...') #4 /Users/richardbspex/Sites/b-spex.com/index.php(5): require_once('/Users/richardb...') #5 {main} thrown in /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/Query/QueryException.php on line 57 This is also the case if I use setParameters() or if I use tokens such as :sessionid, this works correctly when using just where but having the parameter in andWhere causes me problems. This could well be a bug.
admin added the Bug label 2026-01-22 12:51:32 +01:00
admin closed this issue 2026-01-22 12:51:32 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 2, 2010):

Comment created by @beberlei:

can you call getQuery()->getDql() and show the output?

@doctrinebot commented on GitHub (Jul 2, 2010): Comment created by @beberlei: can you call getQuery()->getDql() and show the output?
Author
Owner

@doctrinebot commented on GitHub (Jul 2, 2010):

Comment created by mackstar:

Thanks Benjamin, I should have thought about doing that. It does seem that the andWhere is not being noticed the dql output was as follows

SELECT s FROM Entities\Sessions s WHERE s.sessionid = ?1

maybe andWhere such as I have tried using is not supported? Sorry to waste time...

Cheers

Richard

@doctrinebot commented on GitHub (Jul 2, 2010): Comment created by mackstar: Thanks Benjamin, I should have thought about doing that. It does seem that the andWhere is not being noticed the dql output was as follows SELECT s FROM Entities\Sessions s WHERE s.sessionid = ?1 maybe andWhere such as I have tried using is not supported? Sorry to waste time... Cheers Richard
Author
Owner

@doctrinebot commented on GitHub (Jul 4, 2010):

Comment created by @beberlei:

Richard, yes you are probably using the QueryBuilder wrong. I am not very familiar with the API, but try not using the "add" methods and use the ->where()->andWhere() directly.

@doctrinebot commented on GitHub (Jul 4, 2010): Comment created by @beberlei: Richard, yes you are probably using the QueryBuilder wrong. I am not very familiar with the API, but try not using the "add" methods and use the ->where()->andWhere() directly.
Author
Owner

@doctrinebot commented on GitHub (Jul 4, 2010):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Jul 4, 2010): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#817