Php Mysql事务回滚失败

Php Mysql事务回滚失败,php,mysql,transactions,Php,Mysql,Transactions,我正在使用hikashop(eshop组件)组件创建joomla(2.5),以自动导入客户。问题是我使用的是JDatabase事务,它并没有按预期工作(回滚不起作用)。方法processSingle处理每个客户并返回成功与否。另外,对于调试,还有一个参数可以知道哪个方法(步骤)失败。我已经写了另一个脚本,它使用了相同的回滚结构,并且似乎可以工作,但是这个脚本不行。我试图捕获DatabaseException,但没有异常。有部分代码无法回滚事务 foreach ($this->custome

我正在使用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();
        }
    }
foreach($this->customerList作为$customer){
//开始跟踪数据库条目
$this->db->transactionStart();
$oCustomer=新的stdClass();
$oCustomer->raw_data=$customer;
//从sql注入中转义
$oCustomer=$this->escapeObj($oCustomer);
//在这里,我们处理所有项目,采取一个步骤并完成所有步骤
$methodfailed=“”;
$success=$this->processSingle($oCustomer,$methodfailed);
$processed++;
如果($成功){
$successed++;
//如果成功,请保存更改
$this->db->transactionCommit();
}否则{
$failed++;
echo$this->错误。“
”; echo“失败的方法:.”$methodfailed.“
”; //如果回滚数据库条目失败 $this->db->transactionRollback(); } }

有人有类似的问题吗?顺便说一下,我正在使用PHP/5.3.3-7。

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

检查您的mysql配置是否启用了自动提交模式。关掉它会有帮助。请在此阅读更多有关此的信息


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

是的,表是MyISAM,很抱歉浪费您的时间。@user1597483一点也不浪费时间;这是一个重要/合理的问题。