Laravel 5.1 如何打印最后一条sql语句

DB::connection()->enableQueryLog(); // 开启查询日志

执行的sql行为:

DB::table('xxx'); // 要查看的sql 

$queries = DB::getQueryLog(); // 获取查询日志

print_r($queries); // 即可查看执行的sql,传入的参数等等

 

代码示例:

 

DB::connection()->enableQuerylog();


$state = DB::update(' update user set user_name = "'.$request['name'].'"where id= :id 

and mobile = :mobile ', ['id' => $this->userId'mobile' => $request['tel']]);

$sql = DB::getQueryLog();


var_dump($sql);

 

 

原生Sql语句为:

 

$state = DB::update(' update user set user_name = "'.$request['name'].'" where id= ? 

and mobile = ? ', [$this->userId, $request['tel']]);

 

执行结果:

array(1) {

  [0]=>

  array(3) {

    ["query"]=>

    string(80) " update user set user_name = "么么哒" where id= :id and mobile = :mobile "

    ["bindings"]=>

    array(2) {

      ["id"]=>

      int(8421)

      ["mobile"]=>

      string(11) "157********"

    }

    ["time"]=>

    float(20)

  }

}

 

 

执行结果:

array(1) {

  [0]=>

  array(3) {

    ["query"]=>

    string(72) " update kqc_user set user_name = "么么哒" where id= ? and mobile = ? "

    ["bindings"]=>

    array(2) {

      [0]=>

      int(8421)

      [1]=>

      string(11) "18768112317"

    }

    ["time"]=>

    float(30)

  }

}




本文链接二维码可以保存在本地:保存

| 浏览 (5606) | (0) | (0) | | 2016-04-29 11:25:28 |


相关文章

  1. Mac安装Swoole扩展phpize 时 Cannot find autoconf 解决方法
  2. mac下安装swoole扩展报错PHP Startup Unable to load dynamic library
  3. Laravel 数据库事务
  4. PHP贷款等额本息、等额本金计算月供还款计划公式
  5. Laravel 关闭过滤排除部分路由VerifyCsrfToken 验证
  6. Laravel Horizon监控Redis队列queue