Get query back from PDO prepared statement

Try $statement->queryString.


If you aren't opposed to extending the default \PDO and \PDOStatement object, you might consider looking at:

github.com/noahheck/E_PDOStatement

This extension to PDO allows you to see a full query statement as an example of what might be executed at the database level. It uses regex to interpolate the bound parameters of your PDO statement.

By extending the default \PDOStatement definition, E_PDOStatement is able to offer this enhancement to the default functionality without requiring modification to your normal work flow.

Disclaimer: I created this extension.

I just hope it's helpful to someone else.


The simplest way to achieve what you want is:

$statement->debugDumpParams();

Just make sure you add it after executing the statement.

Tags:

Mysql

Php

Pdo