限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。

Laravel

laravel 数据库的事务操作 +打印sql

事务操作 DB::beginTransaction(); try { DB::insert(...); DB::insert(...); DB::insert(...); DB::commit(); // all good } catch (\Exception $e) { DB::rollback(); // something went wrong }

作者
王明昌
发布时间
最后更新
事务操作
DB::beginTransaction();
try {
    DB::insert(...);
    DB::insert(...);
    DB::insert(...);

    DB::commit();
    // all good
} catch (\Exception $e) {
    DB::rollback();
    // something went wrong
}



打印sql
// DB::connection()->enableQueryLog();#开启执行日志
    $r_parm = objectToArrayLaravel(Db::table('product_sku_info_parm')->select('info_id',DB::raw('count(id) as sumii'))
      ->where($where)
      ->where(function ($query) use ($orWhere) {
        $query->orWhere($orWhere);
     })
      ->orderBy("sumii","desc")
      ->groupBy('info_id')->first());
     // print_r(DB::getQueryLog());
0/500
友善分享您的看法。
反馈邮箱