public function test1()
{
Db::startTrans();
// 事務
try{
// 第1條數據更新id 18
$a=Db::name('user')->where("id", 15)->update(['ledou' => 8888888888]);
// 判斷是否更新成功
if (!$a) {
throw new \Exception("第1條數據更新失敗");
}
// 第2條數據更新 id 9
$b= Db::name('order')->where('id',9)
->update(['status' => 8]);
// 判斷是否更新成功
if (!$b) {
throw new \Exception("第2條數據更新失敗");
}
// 執行提交操作
Db::commit();
}catch(\Exception $e){
// 回滾事務
Db::rollback();
// 獲取提示信息
dump($e->getMessage());
}
if ($a&$b) {
return json(['code' => 1, 'msg' => '成功']);
}else{
return json(['code' => 0, 'msg' => '失敗']);
}
}