【问题标题】:Mysql transction rollback failsMysql事务回滚失败
【发布时间】:2012-10-05 14:08:55
【问题描述】:

我正在使用 hikashop(eshop 组件)组件创建 joomla(2.5) 以自动导入客户。问题是我使用的 JDatabase 事务没有按预期工作(回滚不起作用)。方法 processSingle 处理每个客户并返回它成功与否的天气。同样对于调试,还有一个参数可以知道哪个方法(步骤)失败。我编写了另一个使用相同回滚结构的脚本,它似乎可以工作,但这个没有。我试图捕捉 DatabaseException 但没有例外。部分代码回滚事务失败。

foreach ($this->customerList as $customer) {
        // start tracking database entries
        $this->db->transactionStart();

        $oCustomer = new stdClass();
        $oCustomer->raw_data = $customer;
        // escaping from sql injection
        $oCustomer = $this->escapeObj($oCustomer);
        // here we process all items taking one and going through all steps
        $methodfailed = "";
        $success = $this->processSingle($oCustomer, $methodfailed);
        $processed++;
        if ($success) {
            $succeeded++;
            // if succeded save changes
            $this->db->transactionCommit();
        } else {
            $failed++;
            echo $this->error . "<br/>";
            echo "failed method:" . $methodfailed . "<br/>";
            // if failed rollback database entries
            $this->db->transactionRollback();
        }
    }

有人遇到过类似的问题吗?顺便说一句,我使用的是 PHP/5.3.3-7。

【问题讨论】:

    标签: php mysql transactions


    【解决方案1】:

    我不知道transactionStart 做了什么,但只有 InnoDB 表支持事务。我敢打赌你的数据库表是 MyISAM。

    【讨论】:

    • 是的表是 MyISAM,很抱歉浪费您的时间。
    • @user1597483 一点也不浪费时间;这是一个重要/合法的问题。
    【解决方案2】:

    检查你的 mysql 配置是否开启了 autocommit 模式。将其关闭会有所帮助。在此处阅读更多信息http://dev.mysql.com/doc/refman/5.0/en/commit.html

    您还应该检查您的表是否是 InnoDB。 MyISAM 不支持事务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多