我正在寻找一种方法来一次增加多行的值而不需要循环,是否可以在学说中使用? 这是简单的SQL中的查询:
$sql = "UPDATE table set compteur = compteur + 1 where id in ('1','2','3') ";
使用doctrine更新许多行(不递增),我有这个:
$qb = $this->getEntityManager()->createQueryBuilder();
$query = $qb->update('Application\Entity\Table', 'l')
->set('l.compteur', $qb->expr()->literal('8'))
->where("l.id in ('$ids')")
->getQuery();
$retour = $query->execute();
感谢您的任何想法!!
答案 0 :(得分:0)
使用DQL:
$this->getEntityManager()->createQuery('
UPDATE Application\Entity\Table t
SET t.compteur = t.compteur + 1
')
->execute();
答案 1 :(得分:0)
您也可以使用querybuilder做到这一点,
$qb->set('l.compteur', $qb->expr()->sum('l.compteur', 1));