php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60333 fetch_field() length multiplied by 3 in mysqlnd
Submitted: 2011-11-19 02:38 UTC Modified: 2013-02-18 00:35 UTC
Votes:3
Avg. Score:2.3 ± 0.9
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: danielc at analysisandsolutions dot com Assigned:
Status: No Feedback Package: MySQLi related
PHP Version: 5.4SVN-2011-11-19 (SVN) OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
26 + 20 = ?
Subscribe to this entry?

 
 [2011-11-19 02:38 UTC] danielc at analysisandsolutions dot com
Description:
------------
Running PHP 5.4 compiled from svn earlier today.  The "length" values from fetch_field() are multiplied by 3 when building mysqli against mysqlnd.  The values are correct when building against libmysql.

Test script:
---------------
$db = new mysqli(null, $_ENV['MYSQL_TEST_USER'],
    $_ENV['MYSQL_TEST_PASSWD'], $_ENV['MYSQL_TEST_DB'],
    null, $_ENV['MYSQL_TEST_SOCKET']);

$result = $db->query("CREATE TEMPORARY TABLE phptest_fk (
    txt TEXT NULL,
    chr2 CHAR(2) default 'df' NOT NULL,
    chr10 CHAR(10) default 'df' NOT NULL)");
if (!$result) {
    echo "OOPS: $db->error\n";
    exit(1);
}

$result = $db->query("INSERT INTO phptest_fk VALUES ('One', 'c1')");
$result = $db->query("SELECT * FROM phptest_fk");

$info = $result->fetch_field();
echo "$info->name $info->length\n";
$info = $result->fetch_field();
echo "$info->name $info->length\n";
$info = $result->fetch_field();
echo "$info->name $info->length\n";


Expected result:
----------------
txt 65535
chr2 2
chr10 10

Actual result:
--------------
txt 196605
chr2 6
chr10 30

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-21 17:59 UTC] william dot bailey at cowboysfromhell dot co dot uk
I think this might be down to what encoding the connection is using.

The length in bytes of a mysql utf8 CHAR(2) field is 6.

If you issue a $db->query('SET NAMES latin1'); before the CREATE TABLE then you 
should get the results you are expecting.
 [2011-11-21 18:04 UTC] danielc at analysisandsolutions dot com
That may be the case, but having UTF-8 fields is legit and the answers from libmysql and mysqlnd should be the same.
 [2012-01-13 18:09 UTC] danielc at analysisandsolutions dot com
Can this please be fixed before PHP 5.4 goes out the door?
 [2012-01-23 20:59 UTC] johannes@php.net
-Type: Bug +Type: Documentation Problem
 [2012-01-23 20:59 UTC] johannes@php.net
The behavior is correct. We report the same data as we retrieve from the server. The MySQL documentation has more details on this:
http://dev.mysql.com/doc/refman/5.5/en/c-api-data-structures.html

The key part here is that the data is returned in bytes. On a connection using UTF-8 these are 3 bytes per character.

The PHP documentation should be made more clear on this.
 [2012-01-28 00:29 UTC] frozenfire@php.net
Does this issue only arise when using mysqlnd?
 [2012-01-28 00:29 UTC] frozenfire@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: frozenfire
 [2012-01-28 01:09 UTC] danielc at analysisandsolutions dot com
-Status: Feedback +Status: Assigned
 [2012-01-28 01:09 UTC] danielc at analysisandsolutions dot com
It happens with libmysql under certain circumstances too.  I am working to get a straight answer out of the Johannes and Ulf about a related issue and will post back when that becomes available.
 [2012-02-17 05:23 UTC] frozenfire@php.net
-Status: Assigned +Status: Verified -Assigned To: frozenfire +Assigned To:
 [2013-01-07 13:04 UTC] andrey@php.net
Hi,
during handshake the server states its server charset. mysqlnd uses it, libmysql doesn't. libmysql does use the charset set at build time or some ini setting from my.cnf / my.ini. I suppose your server runs with UTF8 as charset thus mysqlnd uses it as connection charset and so reports 3x values.
 
Is this your case?
 [2013-01-07 13:04 UTC] andrey@php.net
-Status: Verified +Status: Feedback
 [2013-02-18 00:35 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC