最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Laravel5.* 打印出執(zhí)行的sql語(yǔ)句的方法

 更新時(shí)間:2017年07月24日 15:22:13   作者:野蠻秘籍  
本篇文章主要介紹了Laravel5.* 打印出執(zhí)行的sql語(yǔ)句的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文介紹了Laravel5.* 打印出執(zhí)行的sql語(yǔ)句的方法,分享給大家,具體如下:

打開(kāi)app\Providers\AppServiceProvider.PHP,在boot方法中添加如下內(nèi)容

5.2以下版本

// 先引入DB 
use DB;
// 或者直接使用 \DB::
 DB::listen(function($sql, $bindings, $time) {
        dump($sql);
      });

5.2及以上版本

use DB;
// 或者直接使用 \DB::
// 只能接受一個(gè)參數(shù)

QueryExecuted {#84 ▼
 +sql: "select * from `posts` where `slug` = ? limit 1"
 +bindings: array:1 [▶]
 +time: 0.59
 +connection: MySqlConnection {#85 ▶}
 +connectionName: "mysql"
}

 DB::listen(function($sql) {
        dump($sql);
        // echo $sql->sql;
        // dump($sql->bindings);
      });

// 如果要放入日志文件中
DB::listen(
  function ($sql) {
    // $sql is an object with the properties:
    // sql: The query
    // bindings: the sql query variables
    // time: The execution time for the query
    // connectionName: The name of the connection

    // To save the executed queries to file:
    // Process the sql and the bindings:
    foreach ($sql->bindings as $i => $binding) {
      if ($binding instanceof \DateTime) {
        $sql->bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
      } else {
        if (is_string($binding)) {
          $sql->bindings[$i] = "'$binding'";
        }
      }
    }

    // Insert bindings into query
    $query = str_replace(array('%', '?'), array('%%', '%s'), $sql->sql);

    $query = vsprintf($query, $sql->bindings);

    // Save the query to file
    $logFile = fopen(
      storage_path('logs' . DIRECTORY_SEPARATOR . date('Y-m-d') . '_query.log'),
      'a+'
    );
    fwrite($logFile, date('Y-m-d H:i:s') . ': ' . $query . PHP_EOL);
    fclose($logFile);
  }
);

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

石泉县| 庆云县| 临海市| 衡阳县| 绥德县| 长汀县| 若尔盖县| 闵行区| 广德县| 合山市| 曲松县| 南陵县| 镇沅| 天气| 长武县| 合作市| 墨脱县| 揭阳市| 平顶山市| 冀州市| 元朗区| 泌阳县| 富阳市| 洪泽县| 囊谦县| 萝北县| 南郑县| 大宁县| 江永县| 车险| 玛沁县| 福鼎市| 香格里拉县| 牡丹江市| 凤翔县| 专栏| 孝昌县| 曲水县| 禄劝| 山阴县| 来安县|