thinkphp 多表事务处理
2018-02-06 10:10
363 查看
try{ $this->user = D('User'); $this->user->startTrans(); //开始事务 $res = $this->user->Saveuser($where,$data); $res1 = $this->user->Saveuser($where,$data); if(!$res||!$res1){ throw new \Exception('数据实例化失败'); } $this->user->commit(); //确认事务 }catch(\Exception $e){ $this->user->rollback(); //回滚 }
/* * 添加酒店和房型 * */ public function insertAll($arr_hotel=array(),$arr_room=array()){ $model = new Model(); $model->startTrans(); $flag=false; $hid = $model->table(C('DB_PREFIX').'hotel')->add($arr_hotel); if( $hid && count($arr_room) ==0 ){//如果没有传入房型的信息则,直接提交数据 $flag=true; }else if( $hid && count($arr_room) >= 0){//存在对应房型信息,则添加对应的酒店编号,并处理提交 for($i=0 ; $i<count($arr_room) ; $i++){ $arr_room[$i]['hid'] = $hid; } $rid = $model->table(C('DB_PREFIX').'room')->addAll($arr_room); if( $rid ){ $model->commit(); $flag=true; } } if(!$flag){ $model->rollback(); }else{ $model->commit(); } return $flag; }
相关文章推荐
- thinkphp 事务处理
- 在存储过程中使用事务处理 sql server 删除多表操作一致性的问题
- thinkPHP5.0框架事务处理操作简单示例
- ThinkPHP实现事务回滚示例代码(附加:PDO的事务处理)
- ThinkPHP学习笔记 事务处理
- thinkphp 框架下 事务处理+琐行 亲自测试 可用
- Thinkphp-事务处理
- thinkphp 多表事务操作
- PHP 处理 MySQL INNODB 事务回滚(ThinkPHP、MySQL、PDO)
- Thinkphp 多表事务
- thinkphp事务处理
- thinkphp 多表事务操作
- thinkphp 的事务回滚处理 和 原始PHP的事务回滚实例
- thinkphp事务处理无效时的解决办法,一击命中!
- ThinkPHP3.1.2中DbOracle.class.php不能实现事务处理的解决方法
- thinkphp事务处理
- thinkphp3.2 多表事务的实例
- ThinkPHP 处理商品添加的时候操作多张表 用事务解决。
- ThinkPHP 事务处理 (事务回滚) 、异常处理
- thinkphp对事务回滚的案例