我的查询获取每次运行的超时错误.它与联接分页.
我想调试sql,但由于我得到一个超时,我看不到它.
我想调试sql,但由于我得到一个超时,我看不到它.
执行前如何查看编译的SQL查询?
一些蛋糕代码:
- $this -> paginate = array(
- 'limit' => '16','joins' => array( array(
- 'table' => 'products','alias' => 'Product','type' => 'LEFT','conditions' => array('ProductModel.id = Product.product_model_id')
- )),'fields' => array(
- 'COUNT(Product.product_model_id) as Counter','ProductModel.name'
- ),'conditions' => array(
- 'ProductModel.category_id' => $category_id,),'group' => array('ProductModel.id')
- );
首先,在app / config / config.PHP中将调试变量设置为2.
然后添加:
在布局的最后.这实际上应该在您的默认蛋糕布局中注释掉.
现在复制查询并使用数据库中的SQL EXPLAIN命令(用于MysqL的链接)来查看DBMS中查询的内容.有关CakePHP调试的详细信息,请查阅here.
由于您的脚本甚至不能渲染您可以尝试从数据源直接获取最新的日志:
- function getLastQuery()
- {
- $dbo = $this->getDatasource();
- $logs = $dbo->getLog();
- $lastLog = end($logs['log']);
- return $lastLog['query'];
- }
由于getDatasource()函数在模型中定义,所以需要在模型中.检查整个$logs变量,看看那里有什么.