Home >Database >Mysql Tutorial >How to See the Actual SQL Query in Doctrine?
When working with Doctrine, a PHP ORM, you may have a need to examine the raw SQL sent to the database to check its syntax or optimize its performance. However, the $q->getSQLQuery() method only returns the prepared statement, leaving you with question marks (?) instead of the actual parameters.
The reason for this is that Doctrine utilizes prepared statements, which enhance database security and performance. It divides the query process into two steps: preparing the statement and sending the parameters. The $query->getSql() method only returns the prepared statement, while the $query->getParameters() method provides the actual values.
Therefore, there is no "real" SQL query that exists on the PHP side, and Doctrine cannot display it. Instead, you will have to manually build the query using the parameters retrieved from $query->getParameters() or employ a tool like MySQL's EXPLAIN PLAN to trace the execution of the query.
The above is the detailed content of How to See the Actual SQL Query in Doctrine?. For more information, please follow other related articles on the PHP Chinese website!