We are using Doctrine, a PHP ORM. I'm developing a query such as this:

$q = Doctrine_Query::create()->select('id')->from('MyTable')

after which within the function I am including various where clauses and things as appropriate, such as this

$q->where('normalisedname = ? OR title = ?', array($string, $originalString))

Afterwards, before execute()-ing that question object, I wish to print the raw SQL to be able to examine it, and do that:

$q->getSQLQuery()

However that only prints the prepared statement, not the entire query. I wish to see what it's delivering towards the MySQL, but rather it's making a prepared statement, including ?'s. Can there be a way to determine the 'full' query?

Doctrine isn't delivering a "real SQL query" towards the database server : it's really using prepared claims, meaning :

  • Delivering the statement, for this to be ready
  • And, then, delivering the parameters
  • and performing the prepared claims

What this means is there's never a "real" SQL query around the PHP side -- so, Doctrine cannot display it.

There's not one other real query, this is the way prepared claims work. The values are bound within the database server, not within the application layer.

See my response to this: http://stackoverflow.com/questions/1786322/in-php-with-pdo-how-to-check-the-final-sql-parametrized-query/1786449#1786449

(Repeated for convenience:)

Using prepared claims with parametrised values isn't simply a different way to dynamically produce a string of SQL. You produce a prepared statement in the database, after which send the parameter values alone.

What exactly is most likely delivered to the database is a PREPARE ..., then SET ... and lastly EXECUTE ....

You will not have the ability to acquire some SQL string like Choose * FROM ..., even when it might produce equivalent results, because no such query was ever really delivered to the database.

You should check the query performed because of your application should you log all of the queries in mysql:

http://dev.mysql.com/doc/refman/5.1/en/query-log.html

you will see more queries not just the one which you're searching for however, you can grep for this.

truly ->getSql() works