zoukankan      html  css  js  c++  java
  • Cakephp在Controller中显示sql语句

    Cakephp在Controller中查询语句一般是:

                  $this->Model->find();

    那么这条语句对应的sql语句是什么呢?

    可以通过下面方法显示:

    1.

    $dbo = ConnectionManager::getDataSource('default');
    $logs = $dbo->getLog();
    $lastLog = end($logs['log']);
    echo $lastLog['query'];

    2.

    $dbo = $this->Model->getDatasource();
    $logData = $dbo->getLog();
    $getLog = end($logData['log']);
    $this->log( $getLog['query']);

    3. 

    /**   * 获取SQL执行的日志 
      * return array    */ 
     function printSQL()  { 
      $sources = ConnectionManager::sourceList();   $logs = array(); 
      foreach ($sources as $source)   { 
       $db =& ConnectionManager::getDataSource($source);    if (!$db->isInterfaceSupported('getLog')) continue;    $logs[$source] = $db->getLog();   } 
      return $logs;  
    }

  • 相关阅读:
    nginx 命令
    nginx 配置文件(windows)
    nginx 配置文件(linux)
    nginx 安装
    什么是REST架构
    名词解释
    建造者模式
    单例模式
    工厂模式
    赋值运算符,拷贝构造函数,clone()方法总结
  • 原文地址:https://www.cnblogs.com/wscrlhs/p/5509660.html
Copyright © 2011-2022 走看看