5

If I have a prepared statement like SELECT * FROM users WHERE userid = :userid, i can read this SQL statement via PDOStatement::$queryString. For logging i want to have the string, which is executed, e.g. ... WHERE userid = 42. How do i get this string?

Florian
  • 3,145
  • 1
  • 27
  • 38
  • 1
    Sounds like you want is PDOStatement->debugDumpParams http://www.php.net/manual/en/pdostatement.debugdumpparams.php – Glass Robot Jun 27 '11 at 10:51

1 Answers1

5

PDOStatement->debugDumpParams is what you want. You may need to use output buffering though as the results are echoed out.

Glass Robot
  • 2,438
  • 19
  • 11
  • It's important to note that the debugDumpParams function will not dump the actual values, and only the parameters. – David Allen Sep 22 '14 at 15:35
  • 1
    The OP is looking for a complete, executable SQL statement with parameters replaced. debugDumpParams() doesn't do that. – matty May 14 '21 at 19:00