Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get query back from PDO prepared statement [duplicate]

Tags:

php

mysql

pdo

Is there a way to retrieve the query that was used to generate a PDO Prepared statement object?

like image 556
ChrisR Avatar asked Feb 11 '10 08:02

ChrisR


People also ask

How do I get a query in PDO?

SELECT query without parameters If there are no variables going to be used in the query, we can use a conventional query() method instead of prepare and execute. $stmt = $pdo->query("SELECT * FROM users"); This will give us an $stmt object that can be used to fetch the actual rows.

What is prepared statement in PDO?

In layman's terms, PDO prepared statements work like this: Prepare an SQL query with empty values as placeholders with either a question mark or a variable name with a colon preceding it for each value. Bind values or variables to the placeholders. Execute query simultaneously.

What does PDO query return?

PDO::query() returns a PDOStatement object, or FALSE on failure.


1 Answers

Try $statement->queryString.

like image 77
Arkh Avatar answered Sep 29 '22 23:09

Arkh