Php ORM原则:如何使用beginTransaction()在同一个表上多次注册
如何使用beginTransaction()在同一数据库表中注册。示例:在产品的多个细节上签名Php ORM原则:如何使用beginTransaction()在同一个表上多次注册,php,orm,doctrine-orm,transactions,Php,Orm,Doctrine Orm,Transactions,如何使用beginTransaction()在同一数据库表中注册。示例:在产品的多个细节上签名 $entityManager->getConnection()->beginTransaction(); try { ... // Last Product id registered $ultimo_id = $table->getId() $num = array(5,2,3); $lote =
$entityManager->getConnection()->beginTransaction();
try {
...
// Last Product id registered
$ultimo_id = $table->getId()
$num = array(5,2,3);
$lote = array(8,6,7);
// The PROBLEM is that only registers the last (in the key case [2]). I did not
$this->mais_produto($num[0], $lote[0], $ultimo_id);
$this->mais_produto($num[1], $lote[1], $ultimo_id);
$this->mais_produto($num[2], $lote[2], $ultimo_id);
$entityManager->getConnection()->commit();
return true;
}
} catch (\Exception $e) {
$entityManager->getConnection()->rollback();
throw $e;
return false;
}
在mais_produto()函数中,可以运行$entityManager->persist($table);$entityManager->flush()写入数据库
如果有人能帮助我,我将不胜感激有什么问题吗?如果您正在访问同一个对象并对同一列执行更新,那么最后一次更新占上风是正常的。我希望每个人都被写入,而不仅仅是最后一次。相信任何人都需要这样做,但到目前为止还没有找到响应。它会写入所有内容:首先用键0中的值更新行。接下来,将这些值替换为键1中的值。上次您将这些值替换为键2中的值。那么,我如何对所有值进行签名?一位同事建议的此链接帮助了我: