我正在嘗試更新我的實體「Vehicule」的某些行數。我不知道它是如何工作的。 我實際上只想修改direction = 5的兩行。這是我用來更新的函數。隨機更新某些行數
public function ValidAction(\OC\UserBundle\Entity\User $direction) {
$qb = $this->getDoctrine()
->getRepository('CarPfeBundle:Vehicule')
->createQueryBuilder('v');
$q = $qb->update ('CarPfeBundle:vehicule v')
->set('v.direction', '?1')
->where('v.direction = ?2')
->setParameter(1, $direction)
->setParameter(2, 5)
->getQuery();
$p = $q->execute();
return $this->redirect($this->generateUrl('demandeveh_afficher'));
}
但上面的代碼更新我的數據庫的所有行。我只需要更新兩行。請幫忙嗎?
您可以指定請問行的ID號?我想要更新的行數爲 –
?其實它是隨機的,我只需要更新任何兩個隨機的行,這是足夠的where語句。我一直在嘗試使用「update top(2)..」,但它不起作用 –
如果是這樣,嘗試隨機找到任何2個車輛:$ q = $ qb-> find($ vehiculeId);並修改這些Vehicule –