Edit report at https://bugs.php.net/bug.php?id=79084&edit=1
ID: 79084
Updated by: cmb@php.net
Reported by: rob-phpbugs at tigertech dot com
Summary: mysqli fetch_array returns different results on PHP
7.3+ with some column names
Status: Open
Type: Bug
Package: MySQLi related
Operating System: Linux
PHP Version: 7.3.13
Block user comment: N
Private report: N
New Comment:
What happens should be similar to
<?php
$a = [];
$a['2007'] = 0;
$a[] = 0;
?>
So I'm surprised that you're reporting that would have been
different with PHP 7.2. I cannot reproduce that.
Previous Comments:
------------------------------------------------------------------------
[2020-01-08 19:30:15] rob-phpbugs at tigertech dot com
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);
------------------------------------------------------------------------
[2020-01-08 19:03:37] 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
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79084&edit=1