rfc:debugging_pdo_prepared_statement_emulation_v2

PHP RFC: Debugging PDO Prepared Statement Emulation v2

Introduction

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.

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.

Debugging PDO Prepared Statement Emulation v2
Real name Yes No
adambaratz (adambaratz)  
guilhermeblanco (guilhermeblanco)  
kguest (kguest)  
krakjoe (krakjoe)  
mariano (mariano)  
mbeccati (mbeccati)  
nikic (nikic)  
reywob (reywob)  
Final result: 7 1
This poll has been closed.

Patches and Tests

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 (d58231dda300b015260ea8fb17c28f8eebf1ec51).

rfc/debugging_pdo_prepared_statement_emulation_v2.txt · Last modified: 2016/12/20 17:44 by adambaratz