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

Tags: mysqli mysql php
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"


Answers

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.

By : hash


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.

By : troelskn


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

By : DreamWerx


This video can help you solving your question :)
By: admin