php - MySQL在删除事务失败后不回滚

标签 php mysql

我正在使用这样的结构:

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/

相关文章:

python - 使用 MySQLDb 处理错误的日期值

php - 使用不同字段查找多个用户名时出现 MySQL 多重连接问题

PHP 防止多个 MySQL 连接

php - PHP : REQUEST_METHOD as basic error handling for html form

php - 如何在 CakePHP 3.x 中的 MySQL IN 子句中使用多个列?

php - 本地主机连接的安全性

MySQL 显示所需类(class)已完成

php - 创建新的 XML 文件并向其写入数据?

php - 如何在 Laravel 6.x 中的 Eloquent 查询中添加模型相关条件?

mysql - 在 where 子句中使用 if 语句