我创建joomla(2.5)与hikashop (eshop组件)组件,以自动导入客户。问题是我使用的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。
发布于 2012-10-05 22:15:55
我不知道transactionStart是做什么的,但只有InnoDB表支持事务。我敢打赌你的DB表是MyISAM的。
发布于 2012-10-05 22:16:15
检查您的mysql配置是否开启了自动提交模式。关闭它可能会有所帮助。点击此处了解更多信息http://dev.mysql.com/doc/refman/5.0/en/commit.html
此外,您还应该检查您的表是否为InnoDB。MyISAM不支持事务。
https://stackoverflow.com/questions/12748092
复制相似问题