|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-01-08 19:03 UTC] rob-phpbugs at tigertech dot com
Description:
------------
If a query has column names that are all numeric, like this:
SELECT * FROM (SELECT 0 as `2007`, 0 as `2008`, 0 as `2020`) AS x;
And you use "fetch_array()" on it, PHP 7.2 gives this result:
Array
(
[0] => 0
[2007] => 0
[1] => 0
[2008] => 0
[2] => 0
[2020] => 0
)
But PHP 7.3 and 7.4 give this result:
Array
(
[0] => 0
[2007] => 0
[2008] => 0
[2009] => 0
[2020] => 0
)
The latter is wrong: it should not contain "2009", and it is missing "[1]" and "[2]".
Test script:
---------------
<?php
$mysqli = mysqli_connect("localhost", "user", "password", "db");
$sql = "SELECT * FROM (SELECT 0 as `2007`, 0 as `2008`, 0 as `2020`) AS x";
$res = $mysqli->query($sql);
$row = $res->fetch_array();
echo print_r($row, 1);
Expected result:
----------------
Array
(
[0] => 0
[2007] => 0
[1] => 0
[2008] => 0
[2] => 0
[2020] => 0
)
Actual result:
--------------
Array
(
[0] => 0
[2007] => 0
[2008] => 0
[2009] => 0
[2020] => 0
)
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 21:00:01 2025 UTC |
I realize I included a confusing double "SELECT" in the example script because of how I was narrowing down the bug originally. That's not necessary and unrelated; the same thing happens with the simpler query of: <?php $mysqli = mysqli_connect("localhost", "user", "password", "db"); $sql = "SELECT 0 as `2007`, 0 as `2008`, 0 as `2020`"; $res = $mysqli->query($sql); $row = $res->fetch_array(); echo print_r($row, 1);I'm not sure I understand what you said, for which I apologize. Are you saying that when you run the test script on both PHP 7.2 and 7.3, it prints the same results? Could you post what the output of the script is in both cases? Here's the output of a test I just did: $ cat test.php <?php $mysqli = mysqli_connect("localhost", "test", "[redacted]", "test"); $sql = "SELECT 0 as `2007`, 0 as `2008`, 0 as `2020`"; $res = $mysqli->query($sql); $row = $res->fetch_array(); print "PHP version: " . phpversion() . "\n"; print_r($row); $ php-7.2 test.php PHP version: 7.2.26 Array ( [0] => 0 [2007] => 0 [1] => 0 [2008] => 0 [2] => 0 [2020] => 0 ) $ php-7.3 test.php PHP version: 7.3.13 Array ( [0] => 0 [2007] => 0 [2008] => 0 [2009] => 0 [2020] => 0 )I just tried your script and get the same results on 7.2 and 7.3: $ ~/php-7.2/sapi/cli/php t042.php Array ( [0] => 0 [2007] => 0 [2008] => 0 [2009] => 0 [2020] => 0 ) $ ~/php-7.3/sapi/cli/php t042.php Array ( [0] => 0 [2007] => 0 [2008] => 0 [2009] => 0 [2020] => 0 ) Do both PHP versions use mysqlnd (rather than libmysql)?this was also broken in 7.2 print_r diff with the new expected array result 'select field_1 as `10`, field_2 as `20`, field_3 as `30` from test_table' ( [0] => zeile 1 - feld 1 [10] => zeile 1 - feld 1 - [1] => zeile 1 - feld 2 + [11] => zeile 1 - feld 2 [20] => zeile 1 - feld 2 - [2] => zeile 1 - feld 3 + [21] => zeile 1 - feld 3 [30] => zeile 1 - feld 3 )