2

I'm creating an insert statement like the following

$stmt = $connection->prepare("INSERT INTO table (first, second, ...) VALUES (?, ?, ...)");
$stmt->bind_param("ss...", $first, $second, ...);

How can I get the filled out query? E.g.

INSERT INTO table (first, second, ...) VALUES ('one','two', ....)

testing
  • 19,681
  • 50
  • 236
  • 417
  • 1
    possible duplicate of [How to view the rendered (raw) query from a MySQLi prepared statement?](http://stackoverflow.com/questions/7101793/how-to-view-the-rendered-raw-query-from-a-mysqli-prepared-statement) – DaveRandom Jan 17 '12 at 15:24
  • Turn on mysql log? http://dev.mysql.com/doc/refman/5.1/en/server-logs.html – Damp Jan 17 '12 at 16:24
  • I'm afraid if I can turn logging on and accessing the log files, because that is a hosted server ... – testing Jan 17 '12 at 16:43

1 Answers1

1

unfortunately you don't.

As I understand it these are assigned lazily and readied for the next execution of the query.

If you need to test in our db client then vardump the quer and the parameters.

$qry = "INSERT INTO table (first, second, ...) VALUES (?, ?, ...)";
$stmt = $connection->prepare( $qry );
$stmt->bind_param("ss...", $first, $second, ...);

var_dump( $qry , "ss...", $first, $second, ... );

Can I sugeest you look at using PDO and consider using bindValue over bindParam if you don't need to execute the query repeatedly.

Ian Wood
  • 6,515
  • 5
  • 34
  • 73
  • No, I don't look at PDO. I have [a problem with NULL](http://stackoverflow.com/questions/8897284/insert-null-value-into-db-field-with-char2-as-type) and I want to know how the `INSERT` statement looks like. – testing Jan 17 '12 at 15:36
  • you mean inserting a null value? not sure with mysqli (long time since I used it) PDO would be bindParam( ':param', $var, PDO::PARAM_INT|PDO::PARAM_NULL); – Ian Wood Jan 17 '12 at 16:36