Is there a way to see a prepared query as it will be executed on the database? [duplicate]

StackOverflow https://stackoverflow.com/questions/305179

  •  08-07-2019
  •  | 
  •  

Question

Possible Duplicate:
PDO Prepared Statements

I'm using the mysqli extension in PHP and I'm wondering, is there possibly any way to see a prepared query as it will be executed on the server, e.g. The query is something like this

select * from table1 where id = ? and name = ?

but I want to see the query after the values are filled in, like this:

select * from table1 where id = 20 and name = "John"
Was it helpful?

Solution

Duplicate of PDO Prepared Statements

Short answer: no. A prepared query will never be converted to the query you expect. It's executed directly by the database server. You can use mysql's query log or PDO's undocumented function debugDumpParams, but both are just approximations.

OTHER TIPS

Turn on mysql query logging and it will log all queries to a text file for you to review.

See it where? If it's your code you have the query and you have the prepared parameters, log them separately or replace in the original query string. If the binding will fail you will get an error, otherwise you should expect the same values to be "filled" in as you specified them.

Its the way most of the times I am debugging mysql quires:

$q = "select * from table1 where id = ".$id." and name = ".$name; echo $q;

The output generates all variables assigned to the query.

Hope I understood you exactly, what you wanted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top