事务最终解决方案

public function index(){
Db::startTrans();
try{
self::changeUserMoney();
Db::commit();
exit(‘success’);
}catch (\Exception $exception){
$err = [
‘code’ => e x c e p t i o n − > g e t C o d e ( ) , ′ m s g ′ = > u r l d e c o d e ( exception->getCode(), 'msg' => urldecode( exception>getCode(),msg=>urldecode(exception->getMessage()),
‘file’ => $exception->getFile(),
‘line’ => e x c e p t i o n − > g e t L i n e ( ) ] ; @ f i l e p u t c o n t e n t s ( ′ e r r o r . t x t ′ , u r l d e c o d e ( j s o n e n c o d e ( exception->getLine() ]; @file_put_contents('error.txt', urldecode(json_encode( exception>getLine()];@fileputcontents(error.txt,urldecode(jsonencode(err)).PHP_EOL ,FILE_APPEND);
throw new Exception($exception->getMessage());
Db::rollback();
}
}
public function changeUserMoney(){
$res=Db::name(‘salesman’)->where(“id”,4)->update([‘status’=>1]);
r e s 1 = D b : : n a m e ( ′ s a l e s m a n ′ ) − > w h e r e ( " i d " , 4 ) − > u p d a t e ( [ ′ a c c o u n t i d ′ = > 14 ] ) ; i f ( e m p t y ( res1=Db::name('salesman')->where("id",4)->update(['account_id'=>14]); if(empty( res1=Db::name(salesman)>where("id",4)>update([accountid=>14]);if(empty(res)){
throw new Exception(‘1000’);
}
if(empty($res1)){
throw new Exception(‘更新失败1!’);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值