ThinkPHP 3.2.3 Mysql事务嵌套支持

ThinkPHP 3.2.3 Mysql事务嵌套支持
需要修改三个文件
1、Library/Think/Model.class.php 
代码如下,第1501行注释掉就好
  1. /**
  2.      * 启动事务
  3.      * @access public
  4.      * @return void
  5.      */
  6.     public function startTrans() {
  7.         //$this->commit();
  8.         $this->db->startTrans();
  9.         return ;
  10.     }
复制代码
2、Library/Think/Db/Driver.class.php
代码如下:
  1.  /**
  2.      * 启动事务
  3.      * @access public
  4.      * @return void
  5.      */
  6.     public function startTrans() {
  7.         $this->transTimes++;
  8.         $this->initConnect(true);
  9.         if ( !$this->_linkID ) return false;
  10.         //数据rollback 支持
  11.         if ($this->transTimes == 1) {
  12.             $this->_linkID->beginTransaction();
  13.         }
  14.         return ;
  15.     }
  16.     /**
  17.      * 用于非自动提交状态下面的查询提交
  18.      * @access public
  19.      * @return boolean
  20.      */
  21.     public function commit() {
  22.         if ($this->transTimes == 1) {
  23.             $result = $this->_linkID->commit();
  24.             $this->transTimes = 0;
  25.             if(!$result){
  26.                 $this->error();
  27.                 return false;
  28.             }
  29.         } else {
  30.             --$this->transTimes;
  31.         }
  32.         return true;
  33.     }
  34.     /**
  35.      * 事务回滚
  36.      * @access public
  37.      * @return boolean
  38.      */
  39.     public function rollback() {
  40.         if ($this->transTimes == 1) {
  41.             $result = $this->_linkID->rollback();
  42.             $this->transTimes = 0;
  43.             if(!$result){
  44.                 $this->error();
  45.                 return false;
  46.             }
  47.         } else {
  48.             --$this->transTimes;
  49.         }
  50.         return true;
  51.     }
复制代码
3、Library/Think/Db/Lite.class.php
代码如下:
  1.  /**
  2.      * 启动事务
  3.      * @access public
  4.      * @return void
  5.      */
  6.     public function startTrans() {
  7.         $this->transTimes++;
  8.         $this->initConnect(true);
  9.         if ( !$this->_linkID ) return false;
  10.         //数据rollback 支持
  11.         if ($this->transTimes == 1) {
  12.             $this->_linkID->beginTransaction();
  13.         }
  14.         return ;
  15.     }
  16.     /**
  17.      * 用于非自动提交状态下面的查询提交
  18.      * @access public
  19.      * @return boolean
  20.      */
  21.     public function commit() {
  22.         if ($this->transTimes == 1) {
  23.             $result = $this->_linkID->commit();
  24.             $this->transTimes = 0;
  25.             if(!$result){
  26.                 $this->error();
  27.                 return false;
  28.             }
  29.         } else {
  30.             --$this->transTimes;
  31.         }
  32.         return true;
  33.     }
  34.     /**
  35.      * 事务回滚
  36.      * @access public
  37.      * @return boolean
  38.      */
  39.     public function rollback() {
  40.         if ($this->transTimes == 1) {
  41.             $result = $this->_linkID->rollback();
  42.             $this->transTimes = 0;
  43.             if(!$result){
  44.                 $this->error();
  45.                 return false;
  46.             }
  47.         } else {
  48.             --$this->transTimes;
  49.         }
  50.         return true;
  51.     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值