方法一:
public function Transaction(){
DB::beginTransaction(); //开启事务
sql1=DB::table(′demo′)−>where(′id′,′6′)−>delete();sql2 = DB::table('errcode')->where('id','4')->delete();
if(rs1&&rs2){ //判断两条同时执行成功
DB::commit(); //提交
return 1;
}else{
DB::rollback(); //回滚
return 0;
}
}
方法二:
public function Transaction(Request request,id)
{
externalAccount=ExternalAccounts::find(id);
DB::beginTransaction();
try {
externalAccount−>fundnumber=876;externalAccount->capital_balance = '阿斯顿发过火';
$externalAccount->save();
DB::commit();
} catch (Exception $e){
DB::rollback();
throw $e;
}
}
- 12
- 13