NEVER WORKS

Somehow, the doctrine does not allow me to compare two values โ€‹โ€‹of the bottom line: the name of the variable and the name of the user.

$qb = $this->getEntityManager()->createQueryBuilder(); $qb ->select('d') ->from('MyBundle:User', 'd') ->where('LOWER(d.firstName) LIKE :fName') ->setParameter('fName', strtolower('%'.$fName.'%')); $result = $qb->getQuery()->execute(); 

only when $ fName has an uppercase string (ie "Rob") will it return results such as "Robert" and "Robbie". But I want that even when $ fName is lowercase ("rob"), these results should appear. It seems d.firstNames are not going down. Why is this so?

+4
source share
3 answers

I found a solution:

  $qb = $this->getEntityManager()->createQueryBuilder(); $qb ->select('u') ->from('MyBundle:User', 'u') ->where($qb->expr()->andX( $qb->expr()->like('LOWER(u.firstName)', '?1'), $qb->expr()->like('LOWER(u.lastName)', '?2') )) ->setParameter('1', '%' . strtolower($firstName) . '%') ->setParameter('2', '%' . strtolower($lastName) . '%'); $result = $qb->getQuery()->execute(); 

It is still curious why the first attempt did not work.

+3
source

you can try

  $query = $em->createQuery("SELECT u FROM Isha\SuvyaBundle\Entity\Useru WHERE u.fName LIKE '%$fName%' "); $result = $query->getResult(); 
0
source
0
source

Source: https://habr.com/ru/post/1490125/


All Articles