我真的不明白如何在 DBAL 中进行交易
我有以下脚本将根据行的 id 更新列。我放了一个在表中不存在的假 id,(因此无法进行更新)但是尽管它是一个事务,但第一次更新被提交。如果其中一项失败,我希望所有交易都会失败。
$conn -> beginTransaction();
try{
$try = $conn->prepare("update table set column = '123' where id = 0"); //column exists
$try->execute();
$try = $conn->prepare("update table set column = '123' where id = 1"); //column exists
$try->execute();
$try = $conn->prepare("update table set column = '123' where id = 120"); //column does not exists
$try->execute();
$try = $conn->commit();
}
catch(Exception $e) {
$try = $conn->rollback();
throw $e;
}
预期结果,没有更新,因为 id = 120 的行不存在 真实结果,所有行都被更新,除了不存在的行。
我提前道歉,但面向对象编程对我来说仍然是南极洲。