cakephp在执行前看到编译的SQL查询

前端之家收集整理的这篇文章主要介绍了cakephp在执行前看到编译的SQL查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的查询获取每次运行的超时错误.它与联接分页.
我想调试sql,但由于我得到一个超时,我看不到它.

执行前如何查看编译的SQL查询

一些蛋糕代码

  1. $this -> paginate = array(
  2. 'limit' => '16','joins' => array( array(
  3. 'table' => 'products','alias' => 'Product','type' => 'LEFT','conditions' => array('ProductModel.id = Product.product_model_id')
  4. )),'fields' => array(
  5. 'COUNT(Product.product_model_id) as Counter','ProductModel.name'
  6. ),'conditions' => array(
  7. 'ProductModel.category_id' => $category_id,),'group' => array('ProductModel.id')
  8. );
首先,在app / config / config.PHP中将调试变量设置为2.

然后添加

  1. <?PHP echo $this->element('sql_dump');?>

在布局的最后.这实际上应该在您的默认蛋糕布局中注释掉.

您现在将可以看到所有进入数据库SQL查询.

现在复制查询并使用数据库中的SQL EXPLAIN命令(用于MysqL链接)来查看DBMS查询内容.有关CakePHP调试的详细信息,请查阅here.

由于您的脚本甚至不能渲染您可以尝试从数据源直接获取最新的日志:

  1. function getLastQuery()
  2. {
  3. $dbo = $this->getDatasource();
  4. $logs = $dbo->getLog();
  5. $lastLog = end($logs['log']);
  6. return $lastLog['query'];
  7. }

由于getDatasource()函数在模型中定义,所以需要在模型中.检查整个$logs变量,看看那里有什么.

猜你在找的PHP相关文章