Page 1 of 1
How do I get a prepared query as it will execute?
Posted: Tue Aug 09, 2011 9:47 am
by psyclo
I'm new to the mysqli prepared statements, and I'm a bit concerned that what I'm sending to the database is not exactly what is being executed. How can I get the code from MySQL that is to be or was executed, with the parameters in place? Used to be I would just set $query = "select stuff from my tables" and right before I ran the query I would just echo "The query is $query" and I'd know exactly what was going on.
Thanks in advance for your help.
Re: How do I get a prepared query as it will execute?
Posted: Tue Aug 09, 2011 10:04 am
by AbraCadaver
So far as I know, you can't. Just trust that it escapes and quotes your values.
Re: How do I get a prepared query as it will execute?
Posted: Tue Aug 09, 2011 2:43 pm
by psyclo
There has to be a way to get the query as submitted to the database with the parameters populated. There just has to be.
Re: How do I get a prepared query as it will execute?
Posted: Tue Aug 09, 2011 2:50 pm
by AbraCadaver
psyclo wrote:There has to be a way to get the query as submitted to the database with the parameters populated. There just has to be.
Good luck. I Thought so too, but doing a var_dump($stmt) yields nothing resembling the query:
Code: Select all
$id = 1;
$stmt = $mysqli->prepare("SELECT* FROM something WHERE id = ?")) {
$stmt->bind_param("i", $id);
Re: How do I get a prepared query as it will execute?
Posted: Wed Aug 10, 2011 9:38 pm
by Pyrite
Try using the General Query Log feature in MySQL.
http://dev.mysql.com/doc/refman/5.1/en/query-log.html
Also, many PHP frameworks log this as well, with certain debug levels turned on (e.g. CakePHP with Debug Level 2).