Symfony 3 Too many parameters Symfony 3 Too many parameters symfony symfony

Symfony 3 Too many parameters


You should use andWhere() methods instead of where().
where() method removes all previous where, but setParameter() does not. That's why he found more parameters than where clauses.

I personally never use where if the condition has no sense to be the first condition, to avoid this kinds of errors.

    if ($data['famille'] != '') {        $query->andWhere('f.id = :famille')                ->setParameter('famille', $data['famille']);    }    if ($data['rds'] == false) {        $query->andWhere('a.stock_actuel > 0');    }    if ($data['recherche'] != '' && $data['recherche'] != null) {        $query->andWhere('a.ref_article LIKE :recherche')                ->setParameter('recherche', '%' . $data['recherche'] . '%');    }

where() php doc

Specifies one or more restrictions to the query result.
Replaces any previously specified restrictions, if any.

andWhere() php doc

Adds one or more restrictions to the query results, forming a logical conjunction with any previously specified restrictions.


My error, in Symfony 4, using Doctrine 2.6 wasToo many parameters: the query defines 0 parameters and you bound 2

The problem was that I wasn't defining the parameters in andWhere method as

$this->createQueryBuilder('q')...->andWhere('q.propertyDate IS NOT NULL') //this also couldn't find anywhere->andWhere('q.parameterName = :parameterName')->setParameters(['q.parameterName' => $parameterName, ...2nd parameter])

As I couldn't find any answer to my problem, but was similar to this one, I thought to maybe help someone who is struggling like I was.