Home >Backend Development >PHP Tutorial >How Can I Verify the Final SQL Query Executed in a Parametrized Query with PDO in PHP?
When using PHP with PDO to access a MySQL database with parametrized queries, there may arise a need to verify the final SQL query that will be executed. However, it is important to note that:
As stated by Ben James, the full SQL query does not exist on the PHP side. This is because the query with tokens and the parameters are sent separately to the database. The full query is only generated on the database side.
As a workaround, you can log all SQL queries to observe the actual queries being executed on the server. In MySQL, this can be achieved by modifying the my.cnf (or my.ini) file and adding the following line:
log=[REPLACE_BY_PATH]/[REPLACE_BY_FILE_NAME]
However, it is crucial to refrain from using this method in a production environment.
The above is the detailed content of How Can I Verify the Final SQL Query Executed in a Parametrized Query with PDO in PHP?. For more information, please follow other related articles on the PHP Chinese website!