您的位置
主页 > 网站技术 > 数据库 > » 正文

PHP中实现MySQL嵌套事务的两种解决方案(3)

来源: 锦尚中国 点击:


public function rollBack()
{
    if ($this->_transactionNestingLevel == 0) {
        throw ConnectionException::noActiveTransaction();
    }

    if ($this->_transactionNestingLevel == 1) {
        $this->_transactionNestingLevel = 0;
        $this->_conn->rollback();
        $this->_isRollbackOnly = false;
    } else if ($this->_nestTransactionsWithSavepoints) {
        $this->rollbackSavepoint($this->_getNestedTransactionSavePointName());
        --$this->_transactionNestingLevel;
    } else {
        $this->_isRollbackOnly = true;
        --$this->_transactionNestingLevel;
    }
}


可以看到处理的方式也很简单,如果level是1,直接rollback,否则就回滚到前面的savepoint。

然后我们继续看下commit函数:

复制代码 代码如下:




首页  - 关于站长圈  - 广告服务  - 联系我们  - 关于站长圈  - 网站地图  - 版权声明