显示控制器的SQL查询 [英] Show SQL query of controller
问题描述
我使用cakephp v3.x和mysql。
I am using cakephp v3.x and mysql.
我想查看控制器的SQL查询。此控制器没有错误,并且已成功运行。
I would like to see the SQL query of a controller. There is no error with this controller and it runs successfully.
public function appGetResult()
{
$this->autoRender = false;
$start_date = $this->request->query['start_date'];
$end_date = $this->request->query['end_date'];
$results = $this->MonthlyReports->getResult($start_date, $end_date);
echo json_encode($results);
}
如何修改控制器代码以显示生成结果时使用的SQL查询?这不是为实际生产使用。
How to modify the controller code to display the SQL query used in generating the results? This is not for actual production use. More for examination.
推荐答案
您可以在CakePHP3上启用查询记录: http://book.cakephp.org/3.0/en/orm/database-basics.html#query-logging
You can turn on query logging on CakePHP3: http://book.cakephp.org/3.0/en/orm/database-basics.html#query-logging
如果您有兴趣进行更多调试等, DebugKit 做了一个惊人的工作。
If you're interested in doing more debugging and such, DebugKit does an amazing job.
这篇关于显示控制器的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!