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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: joseph dot morain at live dot ca
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Tue Apr 23 13:01:29 2024 UTC