如何在运行时查看 DQL 查询准备好的查询?
function get_event($id){
$query = $this->em->createQuery('SELECT e.name,e.date, e.time, e.venue, e.venueaddress,e.parish,e.genre, e.entryprice, e.phone, e.specialguests,
e.weblink, e.otherinfo, e.flyer1, e.flyer2 from Events e WHERE e.id = :id');
$query->setParameter('id', $id);
//CAN I VIEW THE QUERY AT THIS TIME?
$result = $query->getResult();
return $result;
}
function get_event($id){
$query = $this->em->createQuery('SELECT e.name,e.date, e.time, e.venue, e.venueaddress,e.parish,e.genre, e.entryprice, e.phone, e.specialguests,
e.weblink, e.otherinfo, e.flyer1, e.flyer2 from Events e WHERE e.id = :id');
$query->setParameter('id', $id);
//CAN I VIEW THE QUERY AT THIS TIME?
$result = $query->getResult();
return $result;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Haim Evgi 建议的
EchoSqlLogger
会回显日志输出,因此您应该在您的网站上看到它。如果您只想查看 Doctrine 会生成什么 SQL 查询,请使用:
但请注意,参数不包含在该 sql 字符串中,它们显示为占位符 (= ?)。
为了观察 Doctrine 的作用,我最常用的技术是启用 mysql(或您使用的任何数据库)查询日志(不要在负载较重的生产服务器上执行此操作!)。
如果查询日志位于
/var/log/mysql/query.log
下,我只需执行以下操作:(请参阅 tail 命令 了解更多详细信息)
并重新加载执行查询的页面。
The
EchoSqlLogger
as suggested by Haim Evgi, well, echo´s the log output, so you should see it on your website.If you just want to see what SQL query Doctrine would generate, use:
But be aware, parameters are not included in that sql string, they are shown as placeholders (= ?).
The most common technique I use in order to watch what Doctrine does is enabling the mysql (or whatever db you use) query log (dont do this on a production server which is under heavy load!).
If the query log is under
/var/log/mysql/query.log
I just do this:(see tail command for more details)
And reload the page which executes the query.
在教义 2.3.2 中
,现在你可以用 print_r($logger); 打印 $logger
In doctrine 2.3.2
now you can print $logger with print_r($logger);
SQL: SELECT tbl.id AS id0 FROM mytable tbl WHERE tbl.id = ?
参数: id | 1 |整数
SQL: SELECT tbl.id AS id0 FROM mytable tbl WHERE tbl.id = ?
Param: id | 1 | integer