rfc:mysqli_execute_query
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:mysqli_execute_query [2022/04/04 15:45] – created craigfrancis | rfc:mysqli_execute_query [2022/08/04 13:28] (current) – Target Version: PHP 8.2 dharman | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: MySQLi Execute Query ====== | ====== PHP RFC: MySQLi Execute Query ====== | ||
- | * Version: | + | * Version: 1 |
- | * Voting Start: ? | + | * RFC Started: 2022-04-21 |
- | * Voting End: ? | + | * RFC Updated: 2022-05-11 |
- | * RFC Started: 2022-04-04 | + | * Voting Start: 2022-05-11 15:00 UTC / 16:00 BST |
- | * RFC Updated: 2022-04-04 | + | * Voting End: 2022-05-25 15:00 UTC / 16:00 BST |
* Author: Kamil Tekiela, and Craig Francis [craig# | * Author: Kamil Tekiela, and Craig Francis [craig# | ||
- | * Status: | + | * Status: |
+ | * Target Version: PHP 8.2 | ||
* First Published at: https:// | * First Published at: https:// | ||
* GitHub Repo: https:// | * GitHub Repo: https:// | ||
- | * Implementation: | + | * Implementation: |
===== Introduction ===== | ===== Introduction ===== | ||
Line 32: | Line 33: | ||
<code php> | <code php> | ||
$db = new mysqli(' | $db = new mysqli(' | ||
- | |||
- | $sql = ' | ||
$name = ' | $name = ' | ||
- | $type1 = ' | + | $type1 = 1; // Admin |
- | $type2 = ' | + | $type2 = 2; // Editor |
</ | </ | ||
- | Before PHP 8.1, a typical parameterised query would look like this: | + | Traditionally someone might use escaping, which is [[https:// |
<code php> | <code php> | ||
- | $statement = $db->prepare($sql); | + | foreach ($db-> |
- | $statement->bind_param(' | + | print_r($row); |
- | $statement-> | + | } |
+ | </ | ||
- | $result | + | To avoid mistakes, parameterised queries should be used (with a [[https:// |
+ | |||
+ | <code php> | ||
+ | $statement | ||
+ | $statement-> | ||
+ | $statement-> | ||
- | while ($row = $result->fetch_assoc()) { | + | foreach |
print_r($row); | print_r($row); | ||
} | } | ||
Line 57: | Line 62: | ||
<code php> | <code php> | ||
- | $statement = $db-> | + | $statement = $db-> |
$statement-> | $statement-> | ||
- | $result = $statement-> | + | foreach ($statement-> |
+ | print_r($row); | ||
+ | } | ||
+ | </ | ||
- | while ($row = $result->fetch_assoc()) { | + | This proposed function will simplify this even further, by allowing developers to write this in a one line foreach: |
+ | |||
+ | <code php> | ||
+ | foreach | ||
print_r($row); | print_r($row); | ||
} | } | ||
</ | </ | ||
- | The proposed function will simply this even further, by allowing developers to write: | + | In pseudo-code it's basically: |
<code php> | <code php> | ||
- | $result = $db-> | + | function mysqli_execute_query(mysqli |
+ | { | ||
+ | | ||
- | while ($row = $result->fetch_assoc()) { | + | |
- | | + | if (!($driver-> |
+ | return false; | ||
+ | | ||
+ | |||
+ | $stmt-> | ||
+ | if (!($driver-> | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | return $stmt-> | ||
} | } | ||
</ | </ | ||
Line 85: | Line 107: | ||
==== Returning false ==== | ==== Returning false ==== | ||
- | Because the implementation is effectively calling [[https:// | + | The implementation is effectively calling [[https:// |
+ | |||
+ | ==== Properties ==== | ||
+ | |||
+ | Because [[https:// | ||
+ | |||
+ | - int|string **$affected_rows** - use // | ||
+ | - int|string **$insert_id** - use // | ||
+ | - int|string **$num_rows** - also available on // | ||
+ | - int **$param_count** | ||
+ | - int **$field_count** - also available on // | ||
+ | - int **$errno** - use // | ||
+ | - string **$error** - use // | ||
+ | - array **$error_list** - use // | ||
+ | - string **$sqlstate** - use // | ||
+ | - int **$id** | ||
+ | |||
+ | It's also worth noting the error property usage will hopefully reduce, as more developers use // | ||
==== Re-using Statements ==== | ==== Re-using Statements ==== | ||
- | The implementation discards the // | + | The implementation discards the // |
==== Updating Existing Functions ==== | ==== Updating Existing Functions ==== | ||
- | Cannot change // | + | Cannot change // |
Cannot replace the deprecated // | Cannot replace the deprecated // | ||
Line 133: | Line 172: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | ==== Affected Rows ==== | + | None |
- | + | ||
- | Currently // | + | |
- | + | ||
- | ==== Properties ==== | + | |
- | + | ||
- | Because [[https:// | + | |
- | + | ||
- | - int|string **$affected_rows** | + | |
- | - int|string **$insert_id** - can use // | + | |
- | - int|string **$num_rows** - also available on // | + | |
- | - int **$param_count** | + | |
- | - int **$field_count** - also available on // | + | |
- | - int **$errno** - can use // | + | |
- | - string **$error** - can use // | + | |
- | - array **$error_list** - can use // | + | |
- | - string **$sqlstate** - can use // | + | |
- | - int **$id** | + | |
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Line 164: | Line 186: | ||
Accept the RFC | Accept the RFC | ||
- | TODO | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Implementation ===== | ===== Implementation ===== | ||
- | [[https:// | + | [[https:// |
+ | |||
+ | This implementation copies some details to the mysqli object, but not the affected rows. This means // | ||
===== References ===== | ===== References ===== | ||
Line 176: | Line 203: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | TODO | + | None |
rfc/mysqli_execute_query.1649087102.txt.gz · Last modified: 2022/04/04 15:45 by craigfrancis