这时使用$model->startTrans();
会出现:There is already an active transaction
原因是:transTimes 默认为0,$model->commit();不起作用。
/**
* 用于非自动提交状态下面的查询提交
* @access public
* @return boolean
*/
public function commit() {
if ($this->transTimes > 0) {
$result = $this->_linkID->commit();
$this->transTimes = 0;
if(!$result){
$this->error();
return false;
}
}
return true;
}解决方法:修改Driver.class.php startTrans()方法
* 启动事务
* @access public
* @return void
*/
public function startTrans() {
$this->initConnect(true);
if ( !$this->_linkID ) return false;
//数据rollback 支持
if ($this->transTimes == 0) {
$this->_linkID->commit();//增加这一行,强制开启事务前,提交之前的查询。
$this->_linkID->beginTransaction();
}
$this->transTimes++;
return ;
}把commit()方法移到这里,Model.class.php 文件里startTrans方法,可以移除 commit了 /**
* 启动事务
* @access public
* @return void
*/
public function startTrans() {
//$this->commit();这一行可以不要了
$this->db->startTrans();
return ;
} 最佳答案