0

I use PDOStament::execute() to build queries. How to display prepared query after binding values?

Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
  • [You are not the first one with the question.](http://stackoverflow.com/questions/2411182/how-to-debug-pdo-database-queries). In short - there is no easy way – Your Common Sense Oct 02 '13 at 13:57

2 Answers2

0

Prepared Query is never assembled the way you probably think of it. Values are sent to the database driver separately, so there is no "query after binding" to display at any point of PHP execution. If you have a problem with some queries, you can use slow query log at the MySQL side.

Mołot
  • 699
  • 12
  • 36
  • Quite contrary, with PDO it occurs pretty often – Your Common Sense Oct 02 '13 at 13:59
  • @YourCommonSense please post your answer, then. – Mołot Oct 02 '13 at 13:59
  • Also, consider voting to close instead of giving a duplicated answer. Help to keep the site clean. Thank you – Your Common Sense Oct 02 '13 at 13:59
  • @YourCommonSense from my point of view my answer was first. Now it says it was 2 min ago and the other one 1 minute ago. – Mołot Oct 02 '13 at 14:00
  • It is no racing club here either. Thank you in advance for your understanding. – Your Common Sense Oct 02 '13 at 14:01
  • No racing club for me - at the moment of posting my answer was the only one, and yet I'm the only one you are nagging about it. – Mołot Oct 02 '13 at 14:02
  • There shouldn't be no answer from you but a closevote. – Your Common Sense Oct 02 '13 at 14:04
  • 1
    Not everyone plays detective or remembers all relevant questions... Why can't you just vote to close and move on, then? I don't even have the right to vote on this site yet. And any particular reasons to bother only one of answerers? Do you consider me less worthy because of my lower rep or something? – Mołot Oct 02 '13 at 14:07
  • Oh, do not be afraid of the complexity :) The task is not that hard as you probably imagine. Just take a look at the "Related" column on this page. For the question like this you can easily find a prototype. – Your Common Sense Oct 02 '13 at 14:30
0

You don't get that info in a direct fashion - PDO does not have a mechanism to return that to you. See this question for some details and relevant information (including some links to help).

You can get back the raw query and bindings separately, and attempt to create the final query yourself in code.

Otherwise, if you need the "real" final query, I suggest turning on query logging in your database and inspecting those (while in development, not in production!)

Community
  • 1
  • 1
fideloper
  • 12,213
  • 1
  • 41
  • 38