mysql pdo 事务嵌套
2017-09-14 14:45
190 查看
经常会在处理事务的时候出现多个事务嵌套的情况,这个时候最好有一个处理嵌套事务的封装类来处理,就不需要去修改业务代码来兼容这样的问题了。
<?php class database extends PDO { protected $_transTimes = 0; public function beginTransaction() { ++$this->_transTimes; if ($this->_transTimes == 1) { return parent::beginTransaction(); } $this->exec('SAVEPOINT trans' . $this->_transTimes); return $this->_transTimes >= 0; } public function commit() { --$this->_transTimes; if ($this->_transTimes == 0) { return parent::commit(); } return $this->_transTimes >= 0; } public function rollback() { --$this->_transTimes; if ($this->_transTimes == 0) { return parent::rollback(); } $this->exec('ROLLBACK TO trans' .$this->_transTimes + 1); return true; } }
相关文章推荐
- PHP 处理 MySQL INNODB 事务回滚(ThinkPHP、MySQL、PDO)
- MySQL存储过程例子(包含事务,输出参数,嵌套调用)
- PHP PDO操作mysql事务
- MySQL嵌套事务的讨论
- MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等(转)
- php利用pdo进行mysql的事务处理机制
- MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等
- MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等
- mysql嵌套事务的问题
- MySQL的嵌套事务实现
- MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等
- MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等
- MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等
- laravel项目中出现mysql嵌套事务的分析
- 跟着百度学PHP[14]-PDO之Mysql的事务处理2
- MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等
- pdo和原生态mysql连接实现事务
- MySQL嵌套事务的讨论
- MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等
- ThinkPHP 3.2.3 Mysql事务嵌套支持