Doctrine 2: Update query with query builder

Hi I’ve got the following query but it doesn’t seem to work.

$q = $this->em->createQueryBuilder()
    ->update('modelsUser', 'u')
    ->set('u.username', $username)
    ->set('', $email)
    ->where(' = ?1')
    ->setParameter(1, $editId)
$p = $q->execute();

This returns the following error message:

Fatal error: Uncaught exception ‘DoctrineORMQueryQueryException’ with message ‘[Semantical Error] line 0, col 38 near ‘testusername WHERE’: Error: ‘testusername’ is not defined.’ in …

I would be glad of any help


I think you need to use ->set() It’s much safer to make all your values parameters:

$qb = $this->em->createQueryBuilder();
$q = $qb->update('modelsUser', 'u')
        ->set('u.username', ':username')
        ->set('', ':email')
        ->where('' = ':editId')
        ->setParameter('username', $username)
        ->setParameter('email', $email)
        ->setParameter('editId', $editId)
$p = $q->execute();