Something that has always bugged me about using prepared statements, is that you can really only get the query sent to the database by catching it in the logs.
Today, a friend asking me if it was possible to get a prepared statement back from PDO with the values placeholders replaced, finally caught me in a moment where I could do something about it.
I wrote a thin PDO wrapper class that will [imperfectly, I’m sure] return the completed query.
It supports bound parameters, values and the array key->value methods of passing in values to prepared queries. You can see the code and examples below:
This results in the following output:
Hopefully, this will help you get a somewhat better idea of what’s going on :)