tags:

views:

225

answers:

4

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"
A: 

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.

Alexandru Luchian
+4  A: 

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

DreamWerx
+1  A: 

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.

troelskn
Actually if you enable MySQL query logging, it *does* log a prepared query with parameter values interpolated into it. Wacky!
Bill Karwin
Weird stuff that.
troelskn
A: 

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.

hash
I think he means when he prepares "select * from table1 where id = ? and name = ?" and then subsequently executes it providing parameters $id and $name.
Bill Karwin