-1

Possible Duplicate:
Get query back from PDO prepared statement

Exists any method to show, the query executed sql query in PDO Statement object?

Ex:

$sql="SELECT * FROM table WHERE id=?";
$res=$con->prepare($sql);
$res->execute(array(1));

I like to view a query similar this: "SELECT * FROM table WHERE id=1"

Community
  • 1
  • 1
David
  • 1,116
  • 3
  • 18
  • 32
  • Are you wanting to get the query back out, or something like `SELECT * FROM table WHERE id=1`? – Corbin May 28 '12 at 09:12
  • No i no need the query used to generate (before execute) i need the query generated (after execution) this link isn't the same that i try to ask – David May 28 '12 at 10:16

1 Answers1

0

$res->queryString should contain what you need. You can check out the documentation here.

Hkachhia
  • 4,463
  • 6
  • 41
  • 76
Sean
  • 696
  • 2
  • 9
  • 24
  • Really? it variable functions returns-me the same query with ?; The query before execute, I need the query after execute – David May 28 '12 at 10:13
  • I don't think PDO has a method/variable for that. Can I ask why you need this? – Sean May 28 '12 at 12:37
  • I have query with 6 variables (while inside while, while, while) and I will be like copy the query and try to modify manually. This is not important, but it simplify-me the life :p – David May 29 '12 at 07:06
  • You can generate a query log, which might help: http://dev.mysql.com/doc/refman/5.1/en/query-log.html if you are using mysql, or http://stackoverflow.com/questions/123781/logging-all-queries-on-a-sql-server-2008-express-database if you are using sql server. – Sean May 29 '12 at 15:15