Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO queryString with binded data

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?

like image 241
Florian Avatar asked Jun 27 '11 10:06

Florian


People also ask

How do you bind values in PDO?

The PDOStatement::bindValue() function is an inbuilt function in PHP that is used to bind a value to a parameter. This function binds a value to the corresponding named or question mark placeholder in the SQL which is used to prepare the statement.

What is PDO binding?

Binds a PHP variable to a corresponding named or question mark placeholder in the SQL statement that was used to prepare the statement. Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.

What is PDO in database?

PDO is an acronym for PHP Data Objects. PDO is a lean, consistent way to access databases. This means developers can write portable code much easier. PDO is not an abstraction layer like PearDB. PDO is a more like a data access layer which uses a unified API (Application Programming Interface).

What is bind param?

Definition. bindParam is a PHP inbuilt function used to bind a parameter to the specified variable name in a sql statement for access the database record. bindValue, on the other hand, is again a PHP inbuilt function used to bind the value of parameter to the specified variable name in sql statement. 2. Execution.


1 Answers

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

like image 55
Glass Robot Avatar answered Sep 26 '22 01:09

Glass Robot