1

I want to make column name in query as a parameter.

 $this->createQueryBuilder('b')
            ->where(':column  LIKE :term ')
            ->orderBy('b.id', 'ASC')
            ->setParameter('term',  '%'.$term.'%')
            ->setParameter('column','b.name'  )
            ->getQuery()
            ->getResult();

When I use b.name directly it returns results, but once I move it to parameter it returns nothing.

ogbofjnr
  • 1,688
  • 5
  • 19
  • 41
  • 2
    you cannot define the table/column as parameter (see https://stackoverflow.com/a/182353/4111397 for an answer for generic php PDO which is the base on which doctrine works on). The answer also includes an "answer" that to achieve this, you would need to write the parameter directly in the where clause after sanitation/checks. – ejuhjav Aug 02 '19 at 11:23
  • @ejuhjav, Great, thank you – ogbofjnr Aug 02 '19 at 11:26

0 Answers0