Start by _not_ putting parameters directly into the query, but do it like this:

    $q = $this->em->createQuery('SELECT u FROM user u WHERE u.userid LIKE ? OR 
u.name LIKE ? ORDER BY u.userid');
    $q->setParameter(1, '%' . $username . '%');
    $q->setParameter(2, '%' . $username . '%');

or using named parameters:

    $q = $this->em->createQuery('SELECT u FROM user u WHERE u.userid LIKE 
:userid OR u.name LIKE :name ORDER BY u.userid');
    $q->setParameter('userid', '%' . $username . '%');
    $q->setParameter('name', '%' . $username . '%');

-- 
Jasper N. Brouwer
(@jaspernbrouwer)


On 24 Jan 2014, at 14:20, vipul narain Agarwal <[email protected]> 
wrote:

> hi
> I am using following query to retrieve users using like
> 
>             $userQuery = $this->em->createQuery("SELECT u FROM user u WHERE 
> u.userid LIKE '%.$username.%' OR u.name LIKE '%.$username.%' ORDER BY 
> u.userid");
>             $userQuery->setParameter(1, '%' . $username . '%');
>             $userQuery->setParameter(2, '%' . $username . '%');
>             $userQuery->setMaxResults($usersMaxResult);
>             $userData = $userQuery->getResult();
> 
> now when I am giving t__ as search criteria even if there is no userid by 
> this name it is returning more than 30 results..
> can any one explain what is wrong in it ?
> 
> 
> thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to