php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51189 mysql_field_len reporting value incorrectly
Submitted: 2010-03-03 02:01 UTC Modified: 2010-09-27 11:06 UTC
From: ste dot sullivan at gmail dot com Assigned: mysql (profile)
Status: Not a bug Package: MySQL related
PHP Version: Irrelevant OS: Gentoo
Private report: No CVE-ID: None
 [2010-03-03 02:01 UTC] ste dot sullivan at gmail dot com
Description:
------------
I am using Gentoo

Test script:
---------------
$db=mysql_connect("localhost","user","pass");
$q=mysql_query("SELECT * FROM mytable");
for($i=0;$i<mysql_num_fields($q);$i++) {
  $fnames[$i]=mysql_field_name($q,$i);
  echo $fnames[$i]." { ".mysql_field_type($q,$i)." ( ".mysql_field_len($q,$i)." ) }\n";
}

Expected result:
----------------
Name { string ( 50 ) }
Phone { string ( 48 ) }
Email { string ( 255 ) }

Actual result:
--------------
Name { string ( 150 ) }
Phone { string ( 48 ) }
Email { string ( 765 ) }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-03 02:30 UTC] ste dot sullivan at gmail dot com
Ooops - The second expected result should be: Phone { string ( 16 ) }

The version information also seems to have been wiped from my original post:

PHP: 5.2.12-pl0-gentoo
MYSQL Client API: 5.0.84
 [2010-03-21 19:34 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2010-03-21 19:34 UTC] felipe@php.net
Please, post the DDL used to create the table.
 [2010-03-22 09:33 UTC] uw@php.net
-Status: Assigned +Status: No Feedback
 [2010-03-22 09:33 UTC] uw@php.net
Please send DDL = table definition = schema of table "mytable". Thanks!
 [2010-03-22 10:25 UTC] uw@php.net
-Status: No Feedback +Status: Feedback
 [2010-09-27 11:06 UTC] uw@php.net
-Status: Feedback +Status: Bogus
 [2010-09-27 11:06 UTC] uw@php.net
Well, 99.9% sure it is bogus. Let's close. 

mysql_field_len returns MYSQL_FIELD->lenght (C API), which is "The width of the field. This corresponds to the display length, in *bytes*.". The reporter seems to use a CHAR(50) (resp. CHAR(255)) SQL column together with a 3 byte charset: 50 character x 3 bytes per character = 150 bytes.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC