rfc:debugging_pdo_prepared_statement_emulation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:debugging_pdo_prepared_statement_emulation [2016/11/16 23:02]
adambaratz update proposal and reopen vote
rfc:debugging_pdo_prepared_statement_emulation [2018/03/01 23:27] (current)
carusogabriel RFC was implemented in PHP 7.2
Line 1: Line 1:
 ====== PHP RFC: Debugging PDO Prepared Statement Emulation ====== ====== PHP RFC: Debugging PDO Prepared Statement Emulation ======
-  * Version: 0.4+  * Version: 0.3
   * Date: 2016-10-17   * Date: 2016-10-17
   * Author: Adam Baratz adambaratz@php.net   * Author: Adam Baratz adambaratz@php.net
-  * Status: ​In Discussion+  * Status: ​Implemented (in PHP 7.2)
   * First Published at: https://​wiki.php.net/​rfc/​debugging_pdo_prepared_statement_emulation   * First Published at: https://​wiki.php.net/​rfc/​debugging_pdo_prepared_statement_emulation
  
Line 14: Line 14:
  
 ===== Proposal ===== ===== Proposal =====
-People who use emulated prepared statements should be able to debug them within userland, without using additional tools. PDO already provides some debug functionality in the form of ''​PDOStatement::​debugDumpParams()''​. ​This method ​would be extended ​to include the parsed query string:+People who use emulated prepared statements should be able to debug them within userland, without using additional tools. PDO already provides some debug functionality in the form of ''​PDOStatement::​debugDumpParams()''​. ​The goal would be to offer another slice on PDO internals, not to create another path for developers to communicate with a database. I propose a new method, ''​PDOStatement::​activeQueryString()''​:
  
 <code php> <code php>
-/* Execute a prepared statement by binding PHP variables */ +$db new PDO(...);
-$calories ​150; +
-$colour = '​red'​;+
  
-$sth = $dbh->prepare('​SELECT ​name, colour, calories +// works with statements without bound values 
-    FROM fruit +$stmt = $db->query('​SELECT ​1'); 
-    WHERE calories < ? AND colour = ?'); +var_dump($stmt->activeQueryString()); // =string(8"​SELECT 1"
-$sth->​bindParam(1, $calories, PDO::​PARAM_INT);​ +
-$sth->bindValue(2, $colour, PDO::​PARAM_STR); +
-$sth->execute();+
  
-$sth->debugDumpParams();+$stmt = $db->prepare('​SELECT :​string'​);​ 
 +$stmt->​bindValue(':​string',​ '​foo'​);
  
-/*+// returns unparsed query before execution 
 +var_dump($stmt->​activeQueryString());​ // => string(14) "​SELECT :​string"​
  
-Output: +// returns parsed query after execution 
- +$stmt->​execute();​ 
-SQL: [82] SELECT name, colour, calories +var_dump($stmt->​activeQueryString());​ // => string(11) "SELECT 'foo'"​
-    FROM fruit +
-    WHERE calories < ? AND colour ​+
-Parsed 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 +
- +
-*/+
 </​code>​ </​code>​
  
-The "​Parsed SQL" section will only be shown if the prepared statement emulation is enabled.+Since this would be a debug tool, the method shouldn'​t affect the state of the ''​PDOStatement''​ instance. For example, this method shouldn'​t trigger parsing or errors. You usually don't know something went wrong with the parsing until after execution, anyway. This means the method simply retrieves a value that already exists in memory.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 64: Line 43:
  
 ===== Future Scope ===== ===== Future Scope =====
-It's been suggested that PDO shouldn'​t allow prepare statement emulation. ​This new functionality ​would only engage if emulation ​is enabledso it will self-destruct if emulation is dropped.+It's been suggested that PDO shouldn'​t allow prepare statement emulation. ​Since the mssql extension was deprecated in PHP 7 in favor of pdo_dblib, I don't think this is possible. 
 + 
 +It's been suggested that this change ​would turn PDO into a leaky (or leakier) abstraction. I'd counter that this is strictly a tool that allows tests to expand their code coverage. If emulated prepared statements are being kept in PDOwe should be able to test the >700 LoC in the associated query parser.
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
 This project requires a 50%+1 majority. This project requires a 50%+1 majority.
  
-<doodle title="​Debugging PDO Prepared Statement Emulation ​v0.4" auth="​abaratz"​ voteType="​single"​ closed="​false">+<doodle title="​Debugging PDO Prepared Statement Emulation"​ auth="​abaratz"​ voteType="​single"​ closed="​true">
    * Yes    * Yes
    * No    * No
 </​doodle>​ </​doodle>​
 +
 +===== Patches and Tests =====
 +A working implementation with tests: https://​github.com/​php/​php-src/​pull/​2159
  
 ===== References ===== ===== References =====
-Initial discussion of this proposal on the internals mailing list: +Initial discussion of this proposal on the internals mailing list: http://​marc.info/?​l=php-internals&​m=147638162506291&​w=2 
-http://​marc.info/?​l=php-internals&​m=147638162506291&​w=2 + 
-http://​marc.info/?​l=php-internals&​m=147734024403899&​w=2 +===== Implementation ===== 
-http://marc.info/?l=php-internals&​m=147673258418764&​w=2+This feature was implemented in PHP 7.([[https://github.com/php/php-src/​commit/​83086d9a72675bad2b2560c6f427d0c1f1d1eba0|83086d9a72675bad2b2560c6f427d0c1f1d1eba0]]).
rfc/debugging_pdo_prepared_statement_emulation.1479337362.txt.gz · Last modified: 2017/09/22 13:28 (external edit)