php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33123 mysql_field_len() not working with utf-8
Submitted: 2005-05-24 12:39 UTC Modified: 2006-01-06 03:30 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: rober_box at mailforce dot net Assigned: georg (profile)
Status: Not a bug Package: MySQL related
PHP Version: 4.3.11 OS: Gentoo Linux 2005.0
Private report: No CVE-ID: None
 [2005-05-24 12:39 UTC] rober_box at mailforce dot net
Description:
------------
mysql_field_len() doesn't return the correct field len for 
utf-8 fields. Instead it returns the maximum length mysql 
allows (i.e 3 bytes). That way i can't check user input 
for length sanity. 
 
My configuration:  
'./configure' '--prefix=/usr' '--host=i686-pc-linux-gnu' 
'--mandir=/usr/share/man' '--infodir=/usr/share/info' 
'--datadir=/usr/share' '--sysconfdir=/etc' 
'--localstatedir=/var/lib' '--with-apxs2=/usr/sbin/apxs2' 
'--without-db3' '--without-db4' '--without-db2' 
'--without-ndbm' '--with-mcrypt=/usr' '--with-mhash=/usr' 
'--without-interbase' '--without-ming' '--without-swf' 
'--without-sybase' '--with-gdbm=/usr' '--without-fdftk' 
'--without-java' '--without-mcal' '--without-unixODBC' 
'--without-pgsql' '--without-snmp' 
'--with-xpm-dir=/usr/X11R6' '--without-gmp' 
'--without-mssql' '--with-pdflib=/usr' '--with-gd' 
'--enable-gd-native-ttf' '--with-png=/usr' 
'--with-png-dir=/usr' '--with-jpeg=/usr' 
'--with-jpeg-dir=/usr' '--enable-exif' '--with-tiff=/usr' 
'--with-tiff-dir=/usr' '--with-mysql=/usr' 
'--with-mysql-sock=/var/run/mysqld/mysqld.sock' 
'--with-freetype-dir=/usr' '--with-ttf=/usr' 
'--with-t1lib=/usr' '--with-gettext' 
'--with-qtdom=/usr/qt/3' '--with-pspell=/usr' 
'--with-openssl=/usr' '--without-imap' '--without-ldap' 
'--with-dom=/usr' '--with-dom-xslt=/usr' 
'--with-dom-exslt=/usr' '--without-kerberos' '--with-pam' 
'--disable-memory-limit' '--enable-ipv6' '--without-yaz' 
'--disable-debug' '--with-curlwrappers' '--with-curl=/usr' 
'--enable-dbx' '--with-zlib=/usr' '--with-zlib-dir=/usr' 
'--with-sablot=/usr' '--enable-xslt' '--with-xslt-sablot' 
'--with-xmlrpc' '--enable-wddx' '--with-xml' 
'--enable-mbstring=all' '--enable-mbregex' 
'--with-bz2=/usr' '--with-crack=/usr' '--with-cdb' 
'--enable-pcntl' '--enable-bcmath' '--enable-calendar' 
'--enable-dbase' '--enable-filepro' '--enable-ftp' 
'--with-mime-magic=/usr/share/misc/file/magic.mime' 
'--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' 
'--enable-sysvmsg' '--with-iconv' '--enable-shmop' 
'--enable-dio' '--enable-yp' '--without-ncurses' 
'--without-readline' '--enable-inline-optimization' 
'--enable-track-vars' '--enable-trans-sid' 
'--enable-versioning' 
'--with-config-file-path=/etc/php/apache2-php4' 
'--without-pear' '--libdir=/usr/lib/php' 
'--with-pear=/usr/lib/php' 
 
 

Reproduce code:
---------------
$fields = mysql_list_fields($link, $table) or msg_error(mysql_error());
$len = mysql_field_len($fields, $i);
echo $len;


Expected result:
----------------
I expect to see the actual length as shown by issuing a 
SHOW FIELDS FROM table query. For example if a field is 
VARHCHAR(8) i expect to see 8, not 24. 

Actual result:
--------------
24 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-24 14:02 UTC] tony2001@php.net
Doesn't look like a PHP problem to me.
Georg, please confirm it.
 [2005-05-25 16:55 UTC] georg@php.net
Currently MySQL client library doesn't provide an API call to retrieve CHARSET_INFO structure for a specific character set.
So on client side there is currently no way to determine the maximum size in bytes and characters.

This will probably be added into MySQL 5.1
 [2006-01-06 03:30 UTC] sniper@php.net
It's a Mysql thing, not PHP thing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC