====== PHP RFC: Debugging PDO Prepared Statement Emulation v2 ======
* Version: 0.3
* Date: 2016-11-17
* Author: Adam Baratz adambaratz@php.net
* Status: Implemented (in PHP 7.2)
* First Published at: https://wiki.php.net/rfc/debugging_pdo_prepared_statement_emulation_v2
===== Introduction =====
I previously submitted an [[rfc:debugging_pdo_prepared_statement_emulation|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.
===== Proposal =====
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: [82] SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?
Sent SQL: [88] SELECT name, colour, calories
FROM fruit
WHERE calories < 150 AND colour = 'red'
Params: 2
Key: Position #0:
paramno=0
name=[0] ""
is_param=1
param_type=1
Key: Position #1:
paramno=1
name=[0] ""
is_param=1
param_type=2
*/
The "Sent SQL" section will only be shown after a query is executed, if 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. Voting opened on December 7th. It will end on 16 December 2016 at 0:00 UTC.
* Yes
* No
===== Patches and Tests =====
A working implementation with tests: https://github.com/adambaratz/php-src/commit/a030d2f4e6a13f3e6c10484fb5dbc4e8be6576c6
===== References =====
Discussion on the internals mailing list: http://marc.info/?l=php-internals&m=148034706404511&w=2
===== Implementation =====
This feature was implemented in PHP 7.2 ([[https://github.com/php/php-src/commit/d58231dda300b015260ea8fb17c28f8eebf1ec51|d58231dda300b015260ea8fb17c28f8eebf1ec51]]).