php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16923 mysql_fetch_object returning incomplete data
Submitted: 2002-04-30 01:28 UTC Modified: 2002-05-01 17:23 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mark at artshouse dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.2.0 OS: slackware 8.0 (modified)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mark at artshouse dot com
New email:
PHP Version: OS:

 

 [2002-04-30 01:28 UTC] mark at artshouse dot com
This was found in an ongoing project I am upgrading from php 4.0.4pl1

code sample:

$sql='select prodId, prodNum from products';
$result = mysql_query($sql);

do {
print_r($product);
print $product->prodId ." ". $product-prodNum
} while ($product = mysql_fetch_object($result));

print_r ($product) returns:
stdClass Object ( [prodId] => [prodNum] => E-U-00-002)
stdClass Object ( [prodId] => [prodNum] => E-U-00-003)
stdClass Object ( [prodId] => [prodNum] => E-U-00-004)

the real data would be prodId => 1, prodId => 2

the same thing done with mysql_fetch_array works perfectly (exact same sql, etc) 

I tried various loops (do..while, if, while) no changes.

Tested this with php 4.1.2 and 4.2.0 w/ same errors.  Works fine on 4.0.4pl1.

php configure options as follows:

'./configure' \
'--with-mysql=/usr/local' \
'--enable-track-vars' \
'--with-dbase' \
'--with-gd=/usr/local/gd-1.8.4' \
'--with-ttf' \
'--with-t1lib' \
'--with-jpeg-dir' \
'--with-png-dir' \
'--with-tiff-dir' \
'--with-apxs=/usr/local/apache/bin/apxs' \
'--with-config-file-path=/usr/local/apache/conf' \
'--with-pdflib' \
'--enable-ftp' \
'--with-zlib-dir' 

I am unable to provide a backtrace (production server, sorry)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-01 17:21 UTC] mark at artshouse dot com
I finally tracked this down... it was a bad sql call on my 
part (sort of) and a change in behaviour in 
mysql_fetch_object

I did a call like "select * from products left join details 
on products.prodId=details.prodId"

which returns 2 different prodId (one from each 
table)....because of the join and the fact the details 
doesn't always include prodId (i.e. if there is not a 
matching join) the second prodId was NULL

in php 4.0.4pl1 mysql_fetch_object still set a valid prodId 
for everything ( I am assuming it ignored the NULL 
value)...in php 4.0.6 and newer it sets it to the last 
value it got for prodId (again assuming) which is sometimes 
NULL, sometimes a good value

not sure whether this should be a bug or not.  Anyone?

Mark
 [2002-05-01 17:23 UTC] mark at artshouse dot com
Can someone check to see if this needs attention or not?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC