限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。
当前位置:首页 >开发者 >网站框架 >后端框架 >Laravel

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

分类:Laravel时间:2020-05-10浏览:2319
事务操作
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
Share your thoughts respectfully.