This is an old revision of the document!
PHP RFC: Debugging PDO Prepared Statement Emulation v2
- Version: 0.1
- Date: 2016-11-17
- Author: Adam Baratz email@example.com
- Status: In Discussion
- First Published at: https://wiki.php.net/rfc/debugging_pdo_prepared_statement_emulation_v2
I previously submitted an RFC which was accepted and implemented. I had second thoughts about the implementation and would like to replace it with the approach described here. Please see the original RFC for a description of the underlying problem.
PDO already provides some debug functionality in the form of
PDOStatement::debugDumpParams(). This method would be extended to include the parsed query string:
/* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < ? AND colour = ?'); $sth->bindParam(1, $calories, PDO::PARAM_INT); $sth->bindValue(2, $colour, PDO::PARAM_STR); $sth->execute(); $sth->debugDumpParams(); /* Output: SQL:  SELECT name, colour, calories FROM fruit WHERE calories < ? AND colour = ? Parsed SQL:  SELECT name, colour, calories FROM fruit WHERE calories < 150 AND colour = 'red' Params: 2 Key: Position #0: paramno=0 name= "" is_param=1 param_type=1 Key: Position #1: paramno=1 name= "" is_param=1 param_type=2 */
The “Parsed SQL” section will only be shown if the prepared statement emulation is enabled. This would allow this information to be accessed without any API changes. If prepared statement emulation is removed, as some have suggested it should be, this feature would vanish seamlessly.
Backward Incompatible Changes
The original RFC will be released with PHP 7.2. If this RFC is accepted in time for that release, there will be no BC breaks.
Proposed PHP Version(s)
Next PHP 7.x.
Proposed Voting Choices
This project requires a 50%+1 majority.