|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62426 mysqli_fetch_field_direct returns incorrect length on UTF8 fields
Submitted: 2012-06-26 21:48 UTC Modified: 2012-07-02 13:28 UTC
From: robert dot butler at hoa-management dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
 [2012-06-26 21:48 UTC] robert dot butler at hoa-management dot com
When using UTF8 in the database (mySQL 5.5.24-0ubuntu0.12.04.1), fields defined as a certain length aren't returned as the correct length by mysqli_fetch_field_direct. IOW, a char(32) field is shown as actually being 96 chars long because it's 32 * 3 (3 bytes per char instead of one).

The older mysql_field_len correctly reports the length.

Test script:
// Assuming a single table with a single field 'test' defined as char(32)
// and UTF-8 charset.
$connection = = mysqli_connect ('localhost', 'user', 'password');
$query = "SELECT test FROM test_table LIMIT 1";
$result = mysqli_query ($connection, $query);
$field_info = mysqli_fetch_field_direct ($result, 0);
echo $field_info -> length;

Actual result:
Returns 96; should be 32.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-02 13:28 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Returns bytes
 [2012-07-02 13:28 UTC]
-Status: Open +Status: Not a bug
 [2015-07-06 11:53 UTC]
PHP 5.2 actually returned the correct length, while 5.3, 5.4, 5.5 and 5.6 return the triple size.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 17:01:28 2024 UTC