php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37001 returned array (by mysql_fetch_array($res,MYSQL_ASSOC)) has 'weird' keys.
Submitted: 2006-04-06 20:37 UTC Modified: 2006-06-28 01:00 UTC
Votes:3
Avg. Score:2.7 ± 1.2
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: cyclops at prof-x dot net Assigned: georg (profile)
Status: No Feedback Package: MySQL related
PHP Version: 5.1.2 OS: Linux (Debian Stable)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cyclops at prof-x dot net
New email:
PHP Version: OS:

 

 [2006-04-06 20:37 UTC] cyclops at prof-x dot net
Description:
------------
I have some weird behaviour of mysql_fetch_array with mysql_assoc...

- Query: SELECT id, title, text, filename, timedate FROM news WHERE deleted = 'N' ORDER BY timedate DESC LIMIT 0,5

- print_r of array returned by mysql_fetch_array($res, MYSQL_ASSOC):
Array
(
    [#B] => 133
    [   @] => Name
    [@] => Text
    [] => Filename
    [?] => 2006-03-14 14:01:44
)

changing the query into results in this:
- Query: SELECT id, title, text , filename, timedate FROM news WHERE deleted = 'N' ORDER BY timedate DESC LIMIT 0,5

- print_r of array returned by mysql_fetch_array($res, MYSQL_ASSOC):
Array
(
    [id] => 133
    [title] => Name
    [text] => Text
    [filename] => filename
    [timedate] => 2006-03-14 14:01:4
}

Note the space after 'text'. I also have some different result when i change the limit from '0,5' to '1,5'.


This also breaks mysql_fetch_object returning a error:

PHP Fatal error:  Cannot access empty property in /root/text.php on line 29


Reproduce code:
---------------
function GetLastNews($type = NULL) {
        $con = dbConnect();
        $arr = Array();

        $q2 = "SELECT id, title, text , filename, timedate FROM news WHERE deleted = 'N' ORDER BY timedate DESC LIMIT 0,5";
        $res = mysql_query($q2,$con);
        if ($res) {
                while ($news = mysql_fetch_array($res,MYSQL_ASSOC)) {
                        print_r($news);
                }
                dbClose($con);
                return $arr;
        }
        dbClose($con);
        return NULL;
}


Expected result:
----------------
see description

Actual result:
--------------
see description

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-06 20:44 UTC] cyclops at prof-x dot net
This code works in PHP 4.3.10, found the bug when i wanted to upgrade to 5.x.
Mysql version is 4.1.9.
 [2006-04-06 21:18 UTC] tony2001@php.net
What is the version of libmysqlclient? 
What is the version of MySQL server you're connecting to?
 [2006-04-06 21:39 UTC] cyclops at prof-x dot net
Hope this gives you enough information:

[23:37:04](root) elana:~# php phpinfo.php | grep 'Client API'
Client API version => 4.1.9
Client API version => 4.1.9
[23:37:10](root) elana:~# ldconfig -v | grep mysql
        libgmysqlbackend.so.0 -> libgmysqlbackend.so.0.0.0
/usr/local/mysql/lib/mysql:
        libmysqlclient.so.14 -> libmysqlclient.so.14.0.0
        libmysqlclient.so.12 -> libmysqlclient.so.12.0.0
        libmysqlclient_r.so.12 -> libmysqlclient_r.so.12.0.0
        libmysqlclient.so.12 -> libmysqlclient.so.12.0.0
        libmysqlclient_r.so.10 -> libmysqlclient_r.so.10.0.0
        libmysqlclient.so.10 -> libmysqlclient.so.10.0.0
[23:37:18](root) elana:~# /usr/local/mysql/bin/mysql_config 
Usage: /usr/local/mysql/bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/local/mysql/include/mysql]
        --include        [-I/usr/local/mysql/include/mysql]
        --libs           [-L/usr/local/mysql/lib/mysql -lmysqlclient -lcrypt -lnsl -lm -lz]
        --libs_r         [-L/usr/local/mysql/lib/mysql -lmysqlclient_r -lpthread -lcrypt -lnsl -lm -lpthread -lz]
        --socket         [/tmp/mysql.sock]
        --port           [3306]
        --version        [4.1.9]
        --libmysqld-libs [-L/usr/local/mysql/lib/mysql -lmysqld -lpthread -lcrypt -lnsl -lm -lpthread -lrt -lcrypt -lnsl -lm -lz]
[23:37:32](root) elana:~# php -v
PHP 5.1.2 (cli) (built: Apr  6 2006 21:21:42)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
[23:37:48](root) elana:~# ls -al /usr/local/mysql/lib/
total 12
drwxr-sr-x   3 root mysql 4096 Sep  4  2003 .
drwxr-sr-x  11 root mysql 4096 Sep  4  2003 ..
drwxr-sr-x   2 root mysql 4096 Feb 15  2005 mysql
[23:38:16](root) elana:~# ls -al /usr/local/mysql/lib/mysql/
total 2056
drwxr-sr-x  2 root mysql   4096 Feb 15  2005 .
drwxr-sr-x  3 root mysql   4096 Sep  4  2003 ..
-rw-r--r--  1 root mysql  11798 Feb 15  2005 libdbug.a
-rw-r--r--  1 root mysql  43358 Feb 15  2005 libheap.a
-rw-r--r--  1 root mysql  15322 Feb 15  2005 libmerge.a
-rw-r--r--  1 root mysql 317812 Feb 15  2005 libmyisam.a
-rw-r--r--  1 root mysql  27710 Feb 15  2005 libmyisammrg.a
-rw-r--r--  1 root mysql 468356 Feb 15  2005 libmysqlclient.a
-rwxr-xr-x  1 root mysql    877 Feb 15  2005 libmysqlclient.la
lrwxrwxrwx  1 root mysql     24 Feb 15  2005 libmysqlclient.so -> libmysqlclient.so.14.0.0
lrwxrwxrwx  1 root mysql     24 Sep  4  2003 libmysqlclient.so.12 -> libmysqlclient.so.12.0.0
-rwxr-xr-x  1 root mysql 162062 Sep  4  2003 libmysqlclient.so.12.0.0
lrwxrwxrwx  1 root mysql     24 Feb 15  2005 libmysqlclient.so.14 -> libmysqlclient.so.14.0.0
-rwxr-xr-x  1 root mysql 389446 Feb 15  2005 libmysqlclient.so.14.0.0
-rw-r--r--  1 root mysql 239160 Feb 15  2005 libmystrings.a
-rw-r--r--  1 root mysql 259472 Feb 15  2005 libmysys.a
-rw-r--r--  1 root mysql 101448 Feb 15  2005 libnisam.a
-rw-r--r--  1 root mysql   5942 Feb 15  2005 libvio.a
 [2006-06-20 15:17 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-06-28 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 11 07:01:30 2024 UTC