首页 > 代码库 > ThinkPHP 3.2.2 事务
ThinkPHP 3.2.2 事务
1 <?php
2 namespace SMS\Controller;
3 use Think\Controller;
4 class IndexController extends Controller {
5 public function index(){
6 //echo 111;
7 $data[‘operator‘] = ‘Testss‘;
8 M()->startTrans();
9 $result = M(‘feehistory‘)->add($data);
10 $result1 = $result2 = true;
11 if(!empty($result)){
12 $regdelData[‘level‘] = ‘111‘;
13 $result1 = M(‘regdel‘)->add($regdelData);
14
15 $regData[‘level‘] = ‘101‘;
16 $result2 = M(‘reg‘)->where("registryCode=‘13693536752-SJB-HUAX-12345678‘")->save($regData);
17
18 }
19
20 if(!empty($result) && !empty($result1) && !empty($result2) ){
21 M()->commit();
22 //$this->success(‘事物提交‘,__ROOT__);
23 echo ‘事物提交‘;
24 }else{
25 M()->rollback();
26 //$this->error(‘事物回滚‘,__ROOT__);
27 echo ‘事物回滚‘;
28 }
29 }
30 }
2 namespace SMS\Controller;
3 use Think\Controller;
4 class IndexController extends Controller {
5 public function index(){
6 //echo 111;
7 $data[‘operator‘] = ‘Testss‘;
8 M()->startTrans();
9 $result = M(‘feehistory‘)->add($data);
10 $result1 = $result2 = true;
11 if(!empty($result)){
12 $regdelData[‘level‘] = ‘111‘;
13 $result1 = M(‘regdel‘)->add($regdelData);
14
15 $regData[‘level‘] = ‘101‘;
16 $result2 = M(‘reg‘)->where("registryCode=‘13693536752-SJB-HUAX-12345678‘")->save($regData);
17
18 }
19
20 if(!empty($result) && !empty($result1) && !empty($result2) ){
21 M()->commit();
22 //$this->success(‘事物提交‘,__ROOT__);
23 echo ‘事物提交‘;
24 }else{
25 M()->rollback();
26 //$this->error(‘事物回滚‘,__ROOT__);
27 echo ‘事物回滚‘;
28 }
29 }
30 }
ThinkPHP 3.2.2 事务
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。