php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36653 result set returned has wrong (numeric) data
Submitted: 2006-03-08 12:07 UTC Modified: 2006-03-08 12:53 UTC
From: info at newneon dot com Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 5.1.2 OS: Win 2000
Private report: No CVE-ID: None
 [2006-03-08 12:07 UTC] info at newneon dot com
Description:
------------
I have executed an SQL query with multiple joins (left inners and right outers). When displaying the result set using print_r, I get the following result:

[0] => 10005
    [Respondent] => 5
    [1] => 1
    [Result] => 1
    [2] => 0
    [QuestVersion] => 0
    [3] => CHARLIE
    [MachineID] => CHARLIE
    [4] => 911
    [Enqueteur] => 911
    [5] => Feb 15 2006 12:00AM
    [Datum] => Feb 15 2006 12:00AM

Note the difference between result[0] and result[Respondent]

The proper value is the 10005. How come that PHP converts the 10005 into 5?


Reproduce code:
---------------
Query used:

SELECT * FROM Hoofd LEFT JOIN FillingN ON FillingN.CallCode = Hoofd.Respondent RIGHT OUTER JOIN Hoofd2 ON FillingN.CallCode=Hoofd2.Respondent LEFT JOIN Sample ON FillingN.CallCode=Sample.Code WHERE (Hoofd.Result = 1)

Expected result:
----------------
[0] => 10005
    [Respondent] => 10005
    [1] => 1
    [Result] => 1


Actual result:
--------------
[0] => 10005
    [Respondent] => 5
    [1] => 1
    [Result] => 1


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-08 12:10 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-03-08 12:36 UTC] info at newneon dot com
Example source:

<?
	$db = mssql_connect("<server>", "<username>", "<password>");
	mssql_select_db("<database>", $db);

	// query goes wrong
    $query = "SELECT * FROM Hoofd JOIN FillingN ON Hoofd.Respondent = FillingN.CallCode JOIN Hoofd2 ON Hoofd.Respondent=Hoofd2.Respondent JOIN Sample ON Hoofd.Respondent=Sample.Code WHERE (Hoofd.Result = 1) ORDER BY Hoofd.Respondent";
  
    // query below is fine
    // $query = "SELECT Respondent from Hoofd ORDER BY Respondent"; 
	
	$res = mssql_query($query, $db);
	while ($row=mssql_fetch_array($res))
	{
		echo $row['Respondent']."<BR>";
	}
?>

(Field respondent is int 4)
 [2006-03-08 12:45 UTC] info at newneon dot com
Sorry for 'bugging' you!

It appears that in the complete (joined) query there was another field called respondent, which contains different information! So, in fact result[0] and result[Respondent] referred to different information of the result set!
 [2006-03-08 12:53 UTC] derick@php.net
Ok, bogus then.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC