How to Display the Actual Query MySQLdb Executes
In debugging MySQL queries, it can be useful to view the actual query string that MySQLdb runs after parameter insertion. Despite its apparent simplicity, obtaining this information is not immediately obvious.
Initially, it was believed that Cursor.info() could provide the information about the last query executed. However, this method does not exist in MySQLdb version 1.2.2.
After further investigation, it was discovered that the cursor object has an attribute named _last_executed. This attribute stores the last query string executed, even in cases where an exception occurs.
This solution is advantageous over profiling or MySQL query logging as it has minimal performance impact and eliminates the need for additional code or correlating separate log files.
The above is the detailed content of How do I Display the Actual Query MySQLdb Executes?. For more information, please follow other related articles on the PHP Chinese website!