|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-06-03 19:35 UTC] 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"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 19:00:01 2025 UTC |
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.