2

如何将同一个元组上的这两个更新组合成一个操作?

$q = $this->em->createQuery('update \Entity\UserEn u set u.last = :last where u.name = :name');
$q->setParameters( array(
    'last'  => new \DateTime($newLast),
    'name'  => $theUser,

));
$q->getResult();


$q = $this->em->createQuery('update \Entity\UserEn u set u.contribution = :contribution where u.name = :name');
$q->setParameters( array(
    'contribution'  => $this->rContributionUser($theUser),
    'name'          => $theUser,

));
$q->getResult();

我认为一次更新比两次更新便宜。

4

1 回答 1

2

使用逗号分隔两个分配:

$q = $this->em->createQuery('update \Entity\UserEn u set u.last = :last, u.contribution = :contribution where u.name = :name');
$q->setParameters( array(
    'last'         => new \DateTime($newLast),
    'contribution' => $this->rContributionUser($theUser),
    'name'         => $theUser,
));
$q->getResult();
于 2012-08-28T05:11:57.237 回答