php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69673 'mysql_fetch_array' numeric index results corrupted for SELECT numeric.
Submitted: 2015-05-20 14:40 UTC Modified: 2017-05-09 11:11 UTC
From: kpielorz at tdx dot co dot uk Assigned: fjanisze (profile)
Status: Closed Package: MySQL related
PHP Version: 5.6.9 OS: FreeBSD 10.1-R-p19
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kpielorz at tdx dot co dot uk
New email:
PHP Version: OS:

 

 [2015-05-20 14:40 UTC] kpielorz at tdx dot co dot uk
Description:
------------
The function 'mysql_fetch_array()' should (by default) return an array with a numeric index, and a column name index.

A query which includes a "SELECT number" - e.g. "SELECT 1234" in any column corrupts the index count for subsequent columns.

Test script:
---------------
$qTemp = mysql_query( "SELECT a, b, c FROM test" );
$rTemp = mysql_fetch_array( $qTemp );
print_r( $rTemp );

Result:

Array
(
    [0] => apple
    [a] => apple
    [1] => banana
    [b] => banana
    [2] => cherry
    [c] => cherry
)

(Correct)

But, change the query to: "SELECT 7000, a, b, c FROM test" and the resultant 'print_r' is now:

Array
(
    [0] => 7000
    [7000] => 7000
    [7001] => apple
    [a] => apple
    [7002] => banana
    [b] => banana
    [7003] => cherry
    [c] => cherry
)

This is wrong. The "SELECT 7000" has polluted the numeric index. If you use "SELECT a, b, 7000, c" - the index from the 3rd column onwards then gets polluted.

The same code above works perfectly under PHP 5.4.3 - but produces the incorrect result above with PHP 5.6.9



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-09 11:11 UTC] fjanisze@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: fjanisze
 [2017-05-09 11:11 UTC] fjanisze@php.net
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jun 03 00:01:26 2025 UTC