php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47438 mysql_fetch_field ignores zero offset
Submitted: 2009-02-18 15:45 UTC Modified: 2009-02-18 16:35 UTC
From: craig dot marvelley at boxuk dot com Assigned: mysql (profile)
Status: Closed Package: MySQL related
PHP Version: 5.3.0beta1 OS: Windows/Linux
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: craig dot marvelley at boxuk dot com
New email:
PHP Version: OS:

 

 [2009-02-18 15:45 UTC] craig dot marvelley at boxuk dot com
Description:
------------
When calling mysql_fetch_field(), it seems that in PHP 5.3 the offset 
parameter, when set to 0, is being ignored - the current pointer 
offset is returned instead. According to the manual, that should only 
happen if the field offset is not supplied.

I've tested this in PHP 4 and 5.2 but the above behaviour isn't 
repeated.




Reproduce code:
---------------
// connect to database, etc...

$sql = "SELECT * FROM someTable";
$result = mysql_query($sql);

// set the internal pointer to the second field...
mysql_field_seek($result, 1);

// ... but we'll start at the first field (i.e. ignore the pointer)
$i = 0;

while($i<mysql_num_fields($result))
{
  $meta=mysql_fetch_field($result,$i);
  echo $i . "." . $meta->name . "<br />";
  $i++;
}

Expected result:
----------------
For a table with columns like this:

column1 | column2 | column3

I'd expect to see

0. column1
1. column2
2. column3

(This happens in PHP < 5.3beta1)

Actual result:
--------------
I get this:

0. column2
1. column2
2. column3




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-18 16:07 UTC] johannes@php.net
Should be a simple fix, setting to assigned
 [2009-02-18 16:35 UTC] johannes@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Thanks for the report!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Apr 02 07:01:31 2025 UTC