Bug #79084 [Opn]: mysqli fetch_array returns different results on PHP 7.3+ with some column names
| From: | rob-phpbugs at tigertech dot com | Date: | Wed, 08 Jan 2020 19:30:15 +0000 |
| Subject: | Bug #79084 [Opn]: mysqli fetch_array returns different results on PHP 7.3+ with some column names | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224790@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79084&edit=1
ID: 79084
User updated by: rob-phpbugs at tigertech dot com
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:
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);
Previous Comments:
------------------------------------------------------------------------
[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