Bug #81103 [Com]: mysqli_both overwrites numerical indexes
| From: | fffg at gaeeer dot gg | Date: | Thu, 03 Jun 2021 20:37:47 +0000 |
| Subject: | Bug #81103 [Com]: mysqli_both overwrites numerical indexes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234200@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81103&edit=1
ID: 81103
Comment by: fffg at gaeeer dot gg
Reported by: dharman@php.net
Summary: mysqli_both overwrites numerical indexes
Status: Open
Type: Bug
Package: MySQLi related
PHP Version: 7.4.20
Block user comment: N
Private report: N
New Comment:
garbage in, garbage out and a query like that shouldn't exist in any codebase - and if it
exists common sense says USE_BOTH makes no sense
Previous Comments:
------------------------------------------------------------------------
[2021-06-03 20:21:48] dharman@php.net
Sorry, I messed up the test case.
This one should be better:
$res = $mysqli->query("SELECT 'a' AS
0, 'b' AS
0");
The expected result here is
array(2) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
}
The idea is that numerical indices must take precedence over the associative keys. I don't have
a solution for this.
------------------------------------------------------------------------
[2021-06-03 19:55:05] requinix@php.net
So don't use numerical aliases? Or don't use MYSQLI_BOTH?
What kind of solution do you have in mind?
------------------------------------------------------------------------
[2021-06-03 19:35:32] dharman@php.net
Description:
------------
Per the documentation
"If two or more columns of the result have the same field names, the last column will take
precedence and overwrite the earlier data. In order to access multiple columns with the same name,
the numerically indexed version of the row must be used."
When executing a query with numerical column names, associative names overwrite the numerical
indices. For example, in the code below it is impossible to access value 'a' as it has
been overwritten with 'b'
Test script:
---------------
$res = $mysqli->query("SELECT 'abc', 'a' AS 1,
'b' AS 1");
var_dump($res->fetch_array());
Expected result:
----------------
array(4) {
[0]=>
string(3) "abc"
["abc"]=>
string(3) "abc"
[1]=>
string(1) "b"
[2]=>
string(1) "b"
}
Actual result:
--------------
array(4) {
[0]=>
string(3) "abc"
["abc"]=>
string(3) "abc"
[1]=>
string(1) "a"
[2]=>
string(1) "b"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81103&edit=1