1

I have this error:

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

When I'm trying to get getAllOrders() in my Repository:

public function allOrdersQB()
{
    return $this->createQueryBuilder('o')
        ->andWhere('o.state != :canceled')
        ->andWhere('o.state != :receipt_complete')
        ->setParameters(array(
        'receipt_complete' => 'receipt_complete',
        'canceled' => 'canceled',
    ));
}

public function getAllOrders()
{
    return $this->allOrdersQB()
        ->andWhere('o.stateCorp = :stateCorp')
        ->setParameters(array(
            'stateCorp' => 0,
        ))
        ->getQuery()->getResult();
}

I don't understand because I have set all the parameters.

What did I do wrong?

1 Answer 1

2

The setParameters method reset all previous parameters, so you could use the simple setParameter call (see in the source code here), as example:

public function allOrdersQB()
{
    return $this->createQueryBuilder('o')
        ->andWhere('o.state != :canceled')
        ->andWhere('o.state != :receipt_complete')
        ->setParameter('receipt_complete', 'receipt_complete')
        ->setParameter('canceled', 'canceled')
}

public function getAllOrders()
{
    return $this->allOrdersQB()
        ->andWhere('o.stateCorp = :stateCorp')
        ->setParameter('stateCorp', 0)
        ->getQuery()->getResult();
}

Hope this help

Sign up to request clarification or add additional context in comments.

2 Comments

remove : in setParameter() function. Only setParameter('canceled', 'canceled')
It's ok with setPameter, I just had to resolve the same problem in another method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.