#45737 [Fbk->Csd]: mysql_fetch_assoc returns null on duplicate columns in a join and select *

[email protected] ("quixote at toysmakeuspowerful dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
 ID:               45737
 User updated by:  quixote at toysmakeuspowerful dot com
 Reported By:      quixote at toysmakeuspowerful dot com
-Status:           Feedback
+Status:           Closed
 Bug Type:         MySQL related
 Operating System: Windows and Linux
 PHP Version:      5.2.6
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2008-08-07 12:28:09] [email protected]

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-06 23:32:54] 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.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45737&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.