php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19116 mysql_fetch_array wont get associative values
Submitted: 2002-08-26 22:17 UTC Modified: 2002-08-27 01:30 UTC
From: bzink at crewercs dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.2.1 OS: Linux and XP
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: bzink at crewercs dot com
New email:
PHP Version: OS:

 

 [2002-08-26 22:17 UTC] bzink at crewercs dot com
Note: This fails in 4.2.1 and 4.2.2
   
mysql_connect($host, $user, $pass) or
      die("could not connect");
      
   mysql_select_db($database);

   $result = mysql_query("SELECT * FROM $table");

   while ($row = mysql_fetch_array($result)) {
      printf ("Name: " . $row[1] . "--" . $row["first"] . "--" . "<br>" );
   }

   mysql_free_result($result);

Data is placed in the numeric indices, but NOT the associative ones. This fails on dedicated web hosting (JTL net) as well as my on version running on XP. $row[1] gets data, but $row["first"] does not. Also does not work if add the MYSQL_ASSOC parameter nor does the mysql_fetch_assoc() work.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-27 01:26 UTC] georg@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.

Please remember, that the mysql_fetch_array is case sensitive. To see the contents of $row use var_dump($row).
 [2002-08-27 01:30 UTC] georg@php.net
Ups..

I meant the the associative array has case sensitive keys.
 [2003-02-21 08:25 UTC] jg at proz dot com
I don't think this bug is bogus, just difficult to reproduce.  I also experienced this bug, using PHP 4.3.0, when using mysql_fetch_array on a "SELECT *" result set from a table with a large number of columns.  Only the first element of the returned array had the numeric indexed value set but the associative value empty.  To add to the weirdness, the value that should have been available from the associative key was stuck in numeric index number 64, which did not have a corresponding associative key.

Changing the query to select only the columns that I actually needed resolved the problem for me.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 12:01:33 2024 UTC