Bug->Doc #60333 [Opn]: fetch_field() length multiplied by 3 in mysqlnd
| From: | johannes@php.net | Date: | Mon, 23 Jan 2012 20:59:51 +0000 |
| Subject: | Bug->Doc #60333 [Opn]: fetch_field() length multiplied by 3 in mysqlnd | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-7839@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60333&edit=1
ID: 60333
Updated by: johannes@php.net
Reported by: danielc at analysisandsolutions dot com
Summary: fetch_field() length multiplied by 3 in mysqlnd
Status: Open
-Type: Bug
+Type: Documentation Problem
Package: MySQLi related
Operating System: linux
PHP Version: 5.4SVN-2011-11-19 (SVN)
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2012-01-13 18:09:05] danielc at analysisandsolutions dot com
Can this please be fixed before PHP 5.4 goes out the door?
------------------------------------------------------------------------
[2011-11-21 18:04:38] 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.
------------------------------------------------------------------------
[2011-11-21 17:59:23] 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-19 02:38:53] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60333&edit=1