php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45737 mysql_fetch_assoc returns null on duplicate columns in a join and select *
Submitted: 2008-08-06 23:32 UTC Modified: 2008-08-07 14:11 UTC
From: quixote at toysmakeuspowerful dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 5.2.6 OS: Windows and 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: quixote at toysmakeuspowerful dot com
New email:
PHP Version: OS:

 

 [2008-08-06 23:32 UTC] quixote at toysmakeuspowerful dot com
Description:
------------
select a.*,b.* from a join b on a.id=b.id;
mysql_fetch_assoc() returns null for id.

select a.*,b.*,a.id from a join b on a.id=b.id;
Works, since last instance overrides previous as per documentation.

However it should be in the first case that b.id would get returned automatically, since it is the second instance.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-07 12:28 UTC] uw@php.net
Hi,

please give a complete example including table definitions, table data and the MySQL version used.

Works fine for me with 5.2.6 and 5.3 @ Linux @ MySQL 5.0.51b:

nixnutz@ulflinux:~/php-5.2.6> sapi/cli/php  -r '$m = mysql_connect("127.0.0.1", "root", "root"); var_dump($m); mysql_query("USE test", $m); $r = mysql_query("select a.*, b.* from a, b where a.id=b.id", $m); while ($row = mysql_fetch_assoc($r)) var_dump($row);'
resource(4) of type (mysql link)
array(1) {
  ["id"]=>
  string(1) "1"
}
array(1) {
  ["id"]=>
  string(1) "2"
}
array(1) {
  ["id"]=>
  string(1) "3"
}


create table a(id int);                    
insert into a(id) values(1), (2), (3);
create table b(id int);                    
insert into b(id) values(1), (2), (3);

Adding a column after a.id does not change my results.

Ulf

 [2008-08-07 14:11 UTC] quixote at toysmakeuspowerful dot com
After digging through it more, you can file this one under user error.  I was actually joining 6 tables, and one of the tables had a duplicate column name when it shouldn't have, and I didn't notice.

Sorry for the bother, I should have dug a bit deeper.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 12:01:31 2024 UTC