How Do I See The Final Text Of A Query Resulting From A Call To mysqli->prepare?

Posted by Joshua on Stack Overflow See other posts from Stack Overflow or by Joshua
Published on 2010-04-15T19:51:57Z Indexed on 2010/04/15 19:53 UTC
Read the original article Hit count: 275

Filed under:
|
|

After code like this:

$stmt = $mysqli->prepare("SELECT District FROM City WHERE Name=?")) {
$stmt->bind_param("s", $city);
$stmt->execute();
$stmt->bind_result($district);
$stmt->fetch();
printf("%s is in district %s\n", $city, $district);

How Do I See The Actual SQL Statement That Was Executed?

(It Should Look Something Like "SELECT District FROM City WHERE Name='Simi Valley';")

I already realize that in this simplistic case it would be very easy to simply reconstruct the query... but how can I access it in a general way that will work for very complicated prepared statements, and cases where I don't necessarily already understand the intended structure of the query, etc. Isn't there some function or method that can be called on the statement object that will return the actual text of the SQL query, after binding?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql