php - Doctrine 2: Update query with query builder -
hi i've got following query doesn't seem work.
$q = $this->em->createquerybuilder() ->update('models\user', 'u') ->set('u.username', $username) ->set('u.email', $email) ->where('u.id = ?1') ->setparameter(1, $editid) ->getquery(); $p = $q->execute();
this returns following error message:
fatal error: uncaught exception 'doctrine\orm\query\queryexception' message '[semantical error] line 0, col 38 near 'testusername where': error: 'testusername' not defined.' in ...
i glad of help
i think need use expr
->set()
:
$qb = $this->em->createquerybuilder(); $q = $qb->update('models\user', 'u') ->set('u.username', $qb->expr()->literal($username)) ->set('u.email', $qb->expr()->literal($email)) ->where('u.id = ?1') ->setparameter(1, $editid) ->getquery(); $p = $q->execute();
either or make values parameters:
$qb = $this->em->createquerybuilder(); $q = $qb->update('models\user', 'u') ->set('u.username', '?1') ->set('u.email', '?2') ->where('u.id = ?3') ->setparameter(1, $username) ->setparameter(2, $email) ->setparameter(3, $editid) ->getquery(); $p = $q->execute();
Comments
Post a Comment