php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62879 Incorrect Array Size when fetching Array
Submitted: 2012-08-21 16:03 UTC Modified: 2012-08-21 16:13 UTC
From: joseph dot morain at live dot ca Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
 [2012-08-21 16:03 UTC] joseph dot morain at live dot ca
Description:
------------
Hi I'm using PHP 5.4.4 (Didn't see option for this).

I have a trivial table called staff with 3 rows and 1 record 

staff_id : 555
email : baconator_king@baconation.com
password : 1_b@c0n@73_8Ab1Es

whenever I try to fetch array however it multiplies the data by 2!
I've posted a short little program which illustrates my problem. 

There is a similar problem here : https://bugs.php.net/bug.php?id=60333
but it was dealing with a slightly different function so I didn't append that 
bug report. 




Test script:
---------------
include('_commons.php');
$con = dbopen();
$results = mysqli_query($con,'SELECT  * FROM Staff;');
while($row = mysqli_fetch_array($results)){
	foreach($row as $t){
		echo $t.'<br/>';
	}
}
dbclose($con);

Expected result:
----------------
555
baconator_king@baconation.com
1_b@c0n@73_8Ab1Es

Actual result:
--------------
555
555
baconator_king@baconation.com
baconator_king@baconation.com
1_b@c0n@73_8Ab1Es
1_b@c0n@73_8Ab1Es

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-21 16:13 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-08-21 16:13 UTC] rasmus@php.net
mysqli_fetch_array() by default gives you both numeric and associative indices 
for each row. Pass in MYSQLI_ASSOC or MYSQLI_NUM to get just one of them.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 18:01:30 2024 UTC