php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2661 mysql_fetch_field maxlength returns length of data, not max length of field
Submitted: 1999-11-04 02:05 UTC Modified: 1999-11-05 16:55 UTC
From: mbritton at verinet dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 3.0.12 OS: 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: mbritton at verinet dot com
New email:
PHP Version: OS:

 

 [1999-11-04 02:05 UTC] mbritton at verinet dot com
<?php
$host = "localhost";
$user = "nobody";
$database = "varsity";
$password = "";
$conn = mysql_connect($host,$user,$password);
$result = mysql_db_query($database,"select * from people");
while ($row = mysql_fetch_row($result)) {
   for ( $i = 0; $i < mysql_num_fields($result); $i++ ) {
      $field_info = mysql_fetch_field($result,$i);
      print "field,len,value = $field_info->name,$field_info->max_length,$row[$i]<BR>";
   }
}
?>
---------------
OUTPUT:
field,len,value = person_id,1,1
field,len,value = lname,7,Britton
field,len,value = fname,5,Sandi
field,len,value = position,3,Mgr
---------------
Table Desc from mySQL:
+-----------+-------------+------+-----+---------+----------------+
| Field     | Type        | Null | Key | Default | Extra          |
+-----------+-------------+------+-----+---------+----------------+
| person_id | int(11)     |      | PRI | 0       | auto_increment |
| lname     | varchar(50) | YES  |     | NULL    |                |
| fname     | varchar(50) | YES  |     | NULL    |                |
| position  | varchar(50) | YES  |     | NULL    |                |
+-----------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-05 16:55 UTC] rasmus at cvs dot php dot net
I am unable to duplicate this bug.  It can only be a MySQL version issue as far as I can tell.  The exact test case you provided worked fine on PHP-3.0.13/MySQL-3.22.21
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 08:01:29 2025 UTC