How to print out the real sql in Doctrine and Symfony?

Doctrine is not sending a "real SQL query" to the database server : it is actually using prepared statements, which means :
- 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
Show SQL: $sql=$query->getSQL();

Show Parameters: $parameters=$query->getParameters();
In this way, you can generate or print the real sql using Doctrine and Symfony. In my opinion, It will be much easy to debug the errors in the real sql than doctrine prepared query.
Source : http://stackoverflow.com/a/2095467

Comments

Popular Posts