rfc:mysqli_bind_in_execute

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:mysqli_bind_in_execute [2021/02/11 19:10] – created dharmanrfc:mysqli_bind_in_execute [2021/06/11 11:55] (current) – Implemented dharman
Line 1: Line 1:
 ====== PHP RFC: mysqli bind in execute ====== ====== PHP RFC: mysqli bind in execute ======
-  * Version: 0.9+  * Version: 1.1
   * Date: 2021-02-11   * Date: 2021-02-11
   * Author: Kamil Tekiela, dharman@php.net   * Author: Kamil Tekiela, dharman@php.net
-  * Status: Draft+  * Target version: PHP 8.1 
 +  * Implementation: https://github.com/php/php-src/pull/6271 
 +  * Status: Implemented
  
  
Line 10: Line 12:
  
 ===== Proposal ===== ===== Proposal =====
-I would like to propose adding a new optional argument to %%mysqli_stmt::execute()%% same as PDO does with %%PDOStatement::execute()%%. The goal of this proposal is to simplify mysqli usage with a simple fix which does not require major refactoring.+I would like to propose adding a new optional argument to %%mysqli_stmt::execute()%% same as PDO does with %%PDOStatement::execute()%%. The goal of this proposal is to simplify mysqli usage with a simple fix that does not require major refactoring.
  
 This proposal tries to address the following mysqli limitations: This proposal tries to address the following mysqli limitations:
Line 41: Line 43:
 $stmt = $mysqli->prepare('SELECT name FROM users WHERE id IN ('.str_repeat('?,', count($arr) - 1) . '?)'); $stmt = $mysqli->prepare('SELECT name FROM users WHERE id IN ('.str_repeat('?,', count($arr) - 1) . '?)');
 $stmt->execute($arr); $stmt->execute($arr);
 +</code>
 +
 +
 +It also works in procedural style.
 +<code PHP>
 +$stmt = mysqli_prepare($mysqli, 'INSERT INTO users(id, name) VALUES(?,?)');
 +// $stmt->execute([$id, trim(' Dharman ')]);
 +mysqli_stmt_execute($stmt, [$id, trim(' Dharman ')]);
 +// with the existing alias
 +mysqli_execute($stmt, [++$id, trim(' Dharman ')]);
 </code> </code>
  
Line 51: Line 63:
 While the idea came from PDO bind-in-execute implementation, the mysqli proposal differs in two small ways. While the idea came from PDO bind-in-execute implementation, the mysqli proposal differs in two small ways.
  
-  - Array keys are completely ignored. mysqli doesn't have emulated prepares nor does it have named parameters. Relying on the array keys/indices would make the implementation unnecessarily complex and it would cause unintentional confusion.+  - Only list arrays are allowedThis is because mysqli doesn't have support for named parameters like PDO doesIf an associative array is passed then a ValueError will be thrown. The implementation uses [[rfc:is_list]].
   - Re-binding empty array throws an error in mysqli. PDO simply ignores an empty array and continues to use previously bound values.   - Re-binding empty array throws an error in mysqli. PDO simply ignores an empty array and continues to use previously bound values.
  
Line 59: Line 71:
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-None that I can find.+Classes extending %%mysqli_stmt::execute()%% will be required to specify the additional parameter now.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
-Next PHP 8.x+Next PHP 8.X (8.1)
  
 ===== RFC Impact ===== ===== RFC Impact =====
Line 72: Line 84:
 ==== php.ini Defaults ==== ==== php.ini Defaults ====
 None. None.
- 
-===== Open Issues ===== 
- 
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
Line 85: Line 94:
 Simple yes/no vote. Simple yes/no vote.
  
-===== Patches and Tests ===== +Voting started on 2021-03-08 and ends on 2021-03-27 
-The implementation is available at https://github.com/php/php-src/pull/6271+ 
 +<doodle title="MySQLi bind-in-execute" auth="Dharman" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
 ===== Implementation ===== ===== Implementation =====
-After the project is implemented, this section should contain  +[[https://github.com/php/php-src/pull/6271|PR here]]
-  the version(s) it was merged into +
-  - a link to the git commit(s) +
-  - a link to the PHP manual entry for the feature +
-  - a link to the language specification section (if any)+
  
 ===== References ===== ===== References =====
-Links to external references, discussions or RFCs +https://externals.io/message/113149
- +
-===== Rejected Features =====+
  
rfc/mysqli_bind_in_execute.1613070630.txt.gz · Last modified: 2021/02/11 19:10 by dharman