我正在使用这样的结构:
mysql_query('BEGIN') or die('BEGIN transaction failed!');
$query = "DELETE FROM transaction";
try {
$result = mysql_query($query);
if (!$result) {
throw new Exception('Db error', 1);
}
$query = " INS ERT INTO transaction
SELECT ....."; // just buggy request
$result = mysql_query($query);
if (!$result) {
throw new Exception('Db error', 1);
}
mysql_query('COMMIT') or die('COMMIT transaction failed!');
} catch (Exception $e) {
mysql_query('ROLLBACK') or die('ROLLBACK transaction failed!');
}
但由于某种原因,“删除”事务没有回滚并且表保持为空。
我错过了什么吗?
最佳答案
MySQL Server (version 3.23-max and all versions 4.0 and above) supports transactions with the InnoDB and BDB
请将表引擎更改为innoDB
以支持事务
这是如何更换引擎
ALTER TABLE table_name ENGINE = InnoDB;
关于php - MySQL在删除事务失败后不回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26652313/