2012-08-28 155 views
2

如何將同一個元組上的這兩個更新合併爲一個操作?學說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(); 

我覺得一個更新比2更新便宜。

回答

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(); 
+0

它的工作。感謝您的快速幫助! – user1592714