当事务里执行失败的时候,后面的数据库操作都将失败
2021-02-25 本文已影响0人
苍老师的眼泪
static function index()
{
try {
DB::beginTransaction();
throw new Exception('haha');
DB::commit();
} catch (Exception $e) {
//不会执行
DB::table('logs')->insert([
'description' => '发生数据库异常',
]);
logger($e->getMessage());
}
//不会执行
DB::table('logs')->insert([
'description' => '操作结束',
]);
}
``