我試圖與MySQL數據庫(InnoDB的),但回退不工作PHP測試交易...
這是我的代碼
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "test";
$conn = mysqli_connect($servername, $username, $password, $database);
mysqli_autocommit($conn, FALSE);
mysqli_query($conn,"update person set Balance = 300 where Name = 'Jay'");
if ($conn->affected_rows > 0) {
mysqli_commit($conn);
echo "First Commited <br>";
mysqli_query($conn,"update person set Balance = 3000 where Name = 'Rv'");
if($conn->affected_rows > 0) {
mysqli_commit($conn);
echo "Second Commited <br>";
}else {
mysqli_rollback($conn);
echo "First rollback <br>";
}
}
mysqli_close($conn);
?>
有哪裏不對了? (我也嘗試在PHP的面向對象的風格,從here參考)
SHOW CREATE TABLE人查詢結果
我認爲它與'if($ conn-> affected_rows'之後的提交有關。如示例[here]中所示(http://php.net/manual/en/mysqli.commit.php#refsect1-mysqli .commit-examples)在調用commit之前執行了多個查詢,並且autocommit從未重置爲true – Jelmergu
您能否確切地確認發生了什麼?更新?還是隻有一個?您不應該將過程與面向對象的樣式混合,只需選擇一個。 – mickmackusa
如果第二次查詢的執行則失敗的第一次提交應根據else塊被回滾,但它不工作,承諾不會回退 –