当前位置: 首页>>代码示例>>PHP>>正文


PHP DB::listen方法代码示例

本文整理汇总了PHP中Illuminate\Support\Facades\DB::listen方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::listen方法的具体用法?PHP DB::listen怎么用?PHP DB::listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Facades\DB的用法示例。


在下文中一共展示了DB::listen方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: boot

 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     // If we are in debug mode, listen to database events
     // and log queries to the log file.
     if (env('DB_DEBUG', false)) {
         DB::listen(function ($query) {
             $positional = 0;
             $full_query = '';
             foreach (str_split($query->sql) as $char) {
                 if ($char === '?') {
                     $full_query = $full_query . '"' . $query->bindings[$positional] . '"';
                     $positional++;
                 } else {
                     $full_query = $full_query . $char;
                 }
             }
             logger()->debug(' ---> QUERY DEBUG: ' . $full_query . ' <---');
         });
     }
     $this->publishes([__DIR__ . '/database/migrations/' => database_path('migrations')]);
 }
开发者ID:eveseat,项目名称:services,代码行数:26,代码来源:ServicesServiceProvider.php

示例2: boot

 /**
  * Bootstrap any application services.
  *
  * 这里面能做很多跟监控有关的事情
  *
  * @return void
  */
 public function boot()
 {
     // 监听数据库查询 打印LOG
     DB::listen(function ($sql, $bindings, $time) {
         Log::info('query db' . $sql . ' and the time is ' . $time);
     });
 }
开发者ID:picexif,项目名称:tushuo,代码行数:14,代码来源:AppServiceProvider.php

示例3: boot

 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $monolog = Log::getMonolog();
     $monolog->pushHandler(new LDTHandler());
     DB::listen(function ($query) {
         \DPodsiadlo\LDT\Facades\LDT::query($query);
     });
 }
开发者ID:dpodsiadlo,项目名称:ldt,代码行数:13,代码来源:LDTServiceProvider.php

示例4: logDb

 private function logDb()
 {
     if (env('APP_DEBUG') === true) {
         DB::listen(function ($sql, $bindings, $time) {
             $monolog = new Logger('log');
             $monolog->pushHandler(new StreamHandler($this->dbLogStoragePath), Logger::INFO);
             $monolog->info($sql, compact('bindings', 'time'));
         });
     }
 }
开发者ID:quentin-sommer,项目名称:WebTv,代码行数:10,代码来源:DbLogging.php

示例5: register

 public function register()
 {
     $log = new Logger('db');
     $log->pushHandler(new StreamHandler(storage_path() . '/logs/laravel-db.log'));
     DB::listen(function ($sql, $bindings, $time) use($log) {
         $sql = str_replace(['%', '?'], ['%%', '%s'], $sql);
         $full_sql = vsprintf($sql, $bindings);
         //echo PHP_EOL.'- BEGIN QUERY -'.PHP_EOL.$full_sql.PHP_EOL.'- END QUERY -'.PHP_EOL;
         $log->addInfo($full_sql);
     });
 }
开发者ID:exolnet,项目名称:laravel-module,代码行数:11,代码来源:DatabaseLoggingServiceProvider.php

示例6: boot

 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('home', function ($view) {
         //$viewData = $view->getData();
         //$charts = Location::findOrFail($viewData['']->charts);
         //$view->with('charts', Location::first()->charts);
     });
     // Logs all SQL queries
     DB::listen(function ($sql, $bindings, $time) {
         Log::info($sql);
     });
 }
开发者ID:birgirob,项目名称:TiSDaV,代码行数:17,代码来源:AppServiceProvider.php

示例7: bootWhenLocal

 protected function bootWhenLocal()
 {
     //开发环境
     if (!$this->app->isLocal()) {
         return;
     }
     //日志
     $logger = Log::getMonolog();
     $logger->pushHandler(new BrowserConsoleHandler());
     //DB事件
     DB::listen(function ($query) {
         Log::info('sql :' . $query->sql, ['binding' => $query->bindings, 'time' => $query->time]);
     });
 }
开发者ID:thirdgerb,项目名称:commune-framework,代码行数:14,代码来源:AppServiceProvider.php


注:本文中的Illuminate\Support\Facades\DB::listen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。