#49961 [NoF->Bgs]: Value of "length" column for fetch_fields() is incorrect.
| From: | uw@php.net | Date: | Wed, 04 Nov 2009 20:39:04 +0000 |
| Subject: | #49961 [NoF->Bgs]: Value of "length" column for fetch_fields() is incorrect. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-144273@lists.php.net to get a copy of this message | ||
ID: 49961
Updated by: uw@php.net
Reported By: aavolkoff at gmail dot com
-Status: No Feedback
+Status: Bogus
Bug Type: MySQLi related
Operating System: Linux l9.in-solve.ru 2.6.26-r9-s
PHP Version: 5.2.11
New Comment:
Ah, now I get what is puzzling you: 200 -> 600, sorry missed that on
the first glance.
Not a bug, length is length in bytes. UTF8 uses 3 bytes per character,
200 * 3 = 600.
From the underlying C API documentation:
The width of the field. This corresponds to the display length, in
bytes.
The server determines the length value before it generates the result
set, so this is the minimum length required for a data type capable of
holding the largest possible value from the result column, without
knowing in advance the actual values that will be produced by the query
for the result set.
Previous Comments:
------------------------------------------------------------------------
[2009-10-31 01:00:01] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
------------------------------------------------------------------------
[2009-10-23 20:21:11] aavolkoff at gmail dot com
MySQL charset: UTF-8 Unicode (utf8)
<?
$mysqli = new mysqli("localhost", "root", "");
if (mysqli_connect_errno()) return false;
$db_name = "local";
$query = "CREATE DATABASE
$db_name";
$mysqli->real_query($query);
$mysqli->select_db($db_name);
$table_name = "Users";
$query = "CREATE TABLE ".$table_name."(id int not null
auto_increment, name varchar(200), description varchar(200), primary
key (id)) TYPE=MyISAM";
$mysqli->real_query($query);
$query = "SELECT * FROM $table_name LIMIT 0";
$query_result = $mysqli->real_query($query);
if ($query_result)
{
$mysqli_result = $mysqli->use_result();
$mysqli_fields = $mysqli_result->fetch_fields();
$mysqli_result->free_result();
print_r($mysqli_fields);
}
?>
------------------------------------------------------------------------
[2009-10-23 07:18:21] uw@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
What is needed is all the character sets: MySQL server, client etc.
------------------------------------------------------------------------
[2009-10-23 07:17:16] uw@php.net
Sounds bogus. The mysql extensions in 5.2 forward 1 by 1 what the C API
= Mysql returns. The multiplier of 3 hints that a 3-byte charset gets
used in one case and a 1-byte charset in the other
Without information on the character sets used, this cannot be
verified. You need to provide character set information
------------------------------------------------------------------------
[2009-10-22 18:02:12] aavolkoff at gmail dot com
Description:
------------
Value of "length" column for fetch_fields() is incorrect.
eg: MySQL version: 5.0.37
Reproduce code:
---------------
I have table "Users":
name = "id"; type = "INT"; length = 11.
name = "name"; type = "VARCHAR"; length = 200.
name = "description"; type = "VARCHAR"; length = 200.
Code:
//$mysqli defined earlier
$query = "SELECT * FROM Users LIMIT 0";
$query_result = $mysqli->real_query($query);
if ($query_result)
{
$mysqli_result = $mysqli->use_result();
$mysqli_fields = $mysqli_result->fetch_fields();
$mysqli_result->free_result();
print_r($mysqli_fields);
}
Expected result:
----------------
Array (
[0] => stdClass Object (
[name] => id
[orgname] => id
[table] => Users
[orgtable] => Users
[def] =>
[max_length] => 0
[length] => 11
[charsetnr] => 63
[flags] => 49667
[type] => 3
[decimals] => 0 )
[1] => stdClass Object (
[name] => name
[orgname] => name
[table] => Users
[orgtable] => Users
[def] =>
[max_length] => 0
[length] => 200
[charsetnr] => 33
[flags] => 0
[type] => 253
[decimals] => 0 )
[2] => stdClass Object (
[name] => description
[orgname] => description
[table] => Users
[orgtable] => Users
[def] =>
[max_length] => 0
[length] => 200
[charsetnr] => 33
[flags] => 0
[type] => 253
[decimals] => 0 )
)
Actual result:
--------------
Array (
[0] => stdClass Object (
[name] => id
[orgname] => id
[table] => Users
[orgtable] => Users
[def] =>
[max_length] => 0
[length] => 11
[charsetnr] => 63
[flags] => 49667
[type] => 3
[decimals] => 0 )
[1] => stdClass Object (
[name] => name
[orgname] => name
[table] => Users
[orgtable] => Users
[def] =>
[max_length] => 0
[length] => 600
[charsetnr] => 33
[flags] => 0
[type] => 253
[decimals] => 0 )
[2] => stdClass Object (
[name] => description
[orgname] => description
[table] => Users
[orgtable] => Users
[def] =>
[max_length] => 0
[length] => 600
[charsetnr] => 33
[flags] => 0
[type] => 253
[decimals] => 0 )
)
Parameter "length" of array elements is incorrect (600, but not 200).
When I change length in PhpMyAdmin to 150 code "says" that length is
450.
When I change length in PhpMyAdmin to 1 code "says" that length is 3.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49961&edit=1