當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。