Edit report at https://bugs.php.net/bug.php?id=60333&edit=1
ID: 60333
Comment by: william dot bailey at cowboysfromhell dot co dot uk
Reported by: danielc at analysisandsolutions dot com
Summary: fetch_field() length multiplied by 3 in mysqlnd
Status: Open
Type: Bug
Package: MySQLi related
Operating System: linux
PHP Version: 5.4SVN-2011-11-19 (SVN)
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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