假设我在cakephp 3中有一个查询
$post = $this->Posts->get($id, [
'contain' => ['Postmeta']
]);例如,我想像普通的mysql查询一样打印它
SELECT * FROM posts....有没有人能解释一下我怎么才能做到这一点。请只在cakephp 3环境下回答。是否可以在控制器中像普通mysql查询一样打印它?请不要提及queries.log文件解决方案。由于在queries.log文件中每次执行查询后打开文件并查看查询是花费时间的,所以在cakephp样式中查看谢谢
发布于 2020-07-23 13:11:31
在Controller中,我们需要在查询代码后编写两行代码,如下所示
$post = $this->Posts->get($id, [
'contain' => ['Postmeta']
]);
echo "<pre>";
print_r(debug($post));die; 它将显示所有结果以及sql查询语法。
这里我们使用debug来显示结果和sql查询。
发布于 2017-01-06 13:31:52
查询:
$post = $this->Posts->get($id, [
'contain' => ['Postmeta']
]);对于上述查询的Print/Get SQL语句,可以在控制器中使用如下debug()函数:
$post = $this->Posts->get($id, [
'contain' => ['Postmeta']
]);
debug($post);发布于 2017-01-12 16:45:48
只需写下:
die(print_r($post));https://stackoverflow.com/questions/41492628
复制相似问题