问题描述
我们正在使用 Doctrine,一个 PHP ORM.我正在创建这样的查询:
We're using Doctrine, a PHP ORM. I am creating a query like this:
$q = Doctrine_Query::create()->select('id')->from('MyTable');
然后在函数中我添加了各种 where 子句和适当的东西,就像这样
and then in the function I'm adding in various where clauses and things as appropriate, like this
$q->where('normalisedname = ? OR name = ?', array($string, $originalString));
稍后,在 execute()
-ing 该查询对象之前,我想打印出原始 SQL 以检查它,然后执行以下操作:
Later on, before execute()
-ing that query object, I want to print out the raw SQL in order to examine it, and do this:
$q->getSQLQuery();
然而,这只打印出准备好的语句,而不是完整的查询.我想看看它向 MySQL 发送了什么,但它打印出一个准备好的语句,包括 ?
的.有什么方法可以查看完整"查询?
However that only prints out the prepared statement, not the full query. I want to see what it is sending to the MySQL, but instead it is printing out a prepared statement, including ?
's. Is there some way to see the 'full' query?
推荐答案
Doctrine 没有向数据库服务器发送真正的 SQL 查询":它实际上使用的是准备好的语句,这意味着:
Doctrine is not sending a "real SQL query" to the database server : it is actually using prepared statements, which means :
- 发送语句,以供准备(这是由
$query->getSql()
返回的内容) - 然后,发送参数(由
$query->getParameters()
返回) - 并执行准备好的语句
- Sending the statement, for it to be prepared (this is what is returned by
$query->getSql()
) - And, then, sending the parameters (returned by
$query->getParameters()
) - and executing the prepared statements
这意味着 PHP 端从来没有真正的"SQL 查询——因此,Doctrine 无法显示它.
This means there is never a "real" SQL query on the PHP side — so, Doctrine cannot display it.
这篇关于Doctrine - 如何打印出真正的 sql,而不仅仅是准备好的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!