【发布时间】: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