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
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: info at newneon dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Feb 23 08:01:29 2024 UTC