如何在查询中查看参数? [英] How do I view the parameters in a query?

查看:147
本文介绍了如何在查询中查看参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了调试我的代码,我想看到执行的显式sql查询。

In order to debug my code I would like to see the explicit sql query that is executed.

我用 createQueryBuilder ,我所做的最明显的事情是使用以下原始查询:

I create the query with createQueryBuilder, and the most explicit thing I achieved is having the raw query using:

$qb->getQuery()->getSQL();

问题是,而不是参数,我看到持有人()。
我在网上找到了一些解决方案,但它们是1.3和1.4,对于Symfony-2来说没什么。

The problem is that instead of parameters I see the holders (?). I found some solutions on the web but they are for 1.3 and 1.4, nothing for Symfony-2.

想法?谢谢!

推荐答案

您可以使用 $ query-> getParameters ),所以您可以使用以下方式调试查询:

You can access the parameters used by the placeholders using $query->getParameters(), so you could debug your query using:

$query = $qb->getQuery();
print_r(array(
    'sql'        => $query->getSQL(),
    'parameters' => $query->getParameters(),
));

这篇关于如何在查询中查看参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆