Reputation: 4320
I'm having trouble with some of the more complicated queries sent through PDO using prepared statements. While errorInfo() is useful in showing syntax errors, it doesn't really show logic errors and what is actually part of the query.
Is there a way to echo out the query that PDO executed last? As in, the actual query sent to database? The class should store it somewhere right, because it does send it to database somewhere? Is there a method or some way of catching it?
Currently my debugging system echoes out only the query with ? in place of actual parameters, which is less useful if the error is in logic.
Thanks!
Upvotes: 1
Views: 3784
Reputation: 3484
Consider trying mysql-proxy: http://lamp-dev.com/wp-content/uploads/mysql-proxy.zip
It doesn't matter what extension you use in php , it is just in the middle between php and mysql acting as proxy and shows you all queries "as is". You just need to change DSN in start.bat. Note that this version is windows based.
You'll need to change your connection in php then to connect it to mysql-proxy
Forgot to say that this makes sense only if you use mysql, you did not specify your RDBMS, PDO may work with different drivers
Upvotes: 0
Reputation: 8948
Did you try PDOStatement::debugDumpParams? It gives you detailed information about parameters.
From the manual:
Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, the value, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1).
Upvotes: 1