php - Invalid parameter number: number of bound variables does not match number of tokens in Doctrine -


using doctrine 2 want users contacts of user. table user contains mapping between users. query in function return following error:

invalid parameter number: number of bound variables not match number of tokens.

however best understanding $stris set "b" , $ownerid set "2" , both assigned setparameters function.

 protected function getcontactbysubstring($str, $ownerid) {         echo $str;         echo $ownerid;         $em = $this->getdoctrine()->getentitymanager();         $qb = $em->createquerybuilder();         $qb->add('select', 'u')                 ->add('from', '\paston\verbundle\entity\user u, \paston\verbundle\entity\contact c')                 ->add('where', "c.owner = ?1 , c.contact = u.id , u.username '?2'")                 ->add('orderby', 'u.firstname asc, u.lastname asc')                 ->setparameters(array (1=> $ownerid, 2=> '%'.$str.'%'));          echo $qb->getdql();         $query = $qb->getquery();         $users = $query->getresult();         foreach($users $user)             echo $user->getusername();         exit;         //return $contacts;     } 

don't surround of parameters in query text quotes!

->add('where', "c.owner = ?1 , c.contact = u.id , u.username '?2'") 

should be

->add('where', "c.owner = ?1 , c.contact = u.id , u.username ?2") 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -