php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50021 Predefined Statements doesn't allow Strings with more than 256 letters.
Submitted: 2009-10-27 17:42 UTC Modified: 2009-12-25 19:06 UTC
Votes:7
Avg. Score:4.9 ± 0.3
Reproduced:6 of 7 (85.7%)
Same Version:5 (83.3%)
Same OS:1 (16.7%)
From: novitools dot novi at web dot de Assigned:
Status: Closed Package: MySQLi related
PHP Version: 5.3.0 OS: Windows Vista
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: novitools dot novi at web dot de
New email:
PHP Version: OS:

 

 [2009-10-27 17:42 UTC] novitools dot novi at web dot de
Description:
------------
When you use Predefined Statements you can only read the first 256 words of a string. The same error occurs, when you try to select a text column from the database.

Reproduce code:
---------------
<?php
$Database = new mysqli('localhost', 'root', '');
// that didn't works like expected
$Statement =  $Database->stmt_init();
$sql="SELECT 'You can only read the first 256 words of this text. That is why I must write such a long text, because I must reach the limit of 256 words. The same error occours, when you try to select a text column from the database. But I didn\'t had this error before in a previous version of php.'";
$Statement->prepare($sql);
$Statement->execute();
$Statement->bind_result($Text);
$Statement->fetch();
$Statement->close();
var_dump($Text);
// that works like expected
$Database = new mysqli('localhost', 'root', '');
$sql="SELECT 'You can only read the first 256 words of this text. That is why I must write such a long text, because I must reach the limit of 256 words. The same error occours, when you try to select a text column from the database. But I didn\'t had this error before in a previous version of php.'";
$Result = $Database->query($sql);
$Row = $Result->fetch_row();
$Result->close();
var_dump($Row[0]);
?>

Expected result:
----------------
string(284) "You can only read the first 256 words of this text. That is why I must write such a long text, because I must reach the limit of 256 words. The same error occours, when you try to select a text column from the database. But I didn't had this error before in a previous version of php."
string(284) "You can only read the first 256 words of this text. That is why I must write such a long text, because I must reach the limit of 256 words. The same error occours, when you try to select a text column from the database. But I didn't had this error before in a previous version of php."

Actual result:
--------------
string(256) "You can only read the first 256 words of this text. That is why I must write such a long text, because I must reach the limit of 256 words. The same error occours, when you try to select a text column from the database. But I didn't had this error before i"
string(284) "You can only read the first 256 words of this text. That is why I must write such a long text, because I must reach the limit of 256 words. The same error occours, when you try to select a text column from the database. But I didn't had this error before in a previous version of php."

Note that the first string is only 256 words long.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-29 16:26 UTC] hellbringer at gmail dot com
Works for me in PHP 5.3.0:


<?php

$db = new mysqli('localhost', 'root', '');
$stmt = $db->stmt_init();
$sql = "SELECT 'You can only read the first 256 words of this text. That
is why I must write such a long text, because I must reach the limit of
256 words. The same error occours, when you try to select a text column
from the database. But I didn\'t had this error before in a previous
version of php.'";
$stmt->prepare($sql);
$stmt->execute();
$stmt->bind_result($text);
$stmt->fetch();
$stmt->close();
var_dump(phpversion());
var_dump($db->client_version);
var_dump($db->server_version);
var_dump($db->protocol_version);
var_dump($text);

?>


Output:

string(5) "5.3.0"
int(50005)
int(50132)
int(10)
string(288) "You can only read the first 256 words of this text. That
is why I must write such a long text, because I must reach the limit of
256 words. The same error occours, when you try to select a text column
from the database. But I didn't had this error before in a previous
version of php."
 [2009-10-29 17:07 UTC] novitools dot novi at web dot de
When I run the test from hellbringer at gmail dot com I get a different result. Also the MySQL-Versions are different:

string(5) "5.3.0"
int(50137)
int(50137)
int(10)
string(256) "You can only read the first 256 words of this text.
That
is why I must write such a long text, because I must reach the limit of
256 words. The same error occours, when you try to select a text column
from the database. But I didn't had this error befo"

Are there any setting that can cause this problem?
 [2009-10-29 17:58 UTC] friedrich dot mark at freenet dot de
Same Problem here:
$db = new mysqli('localhost', 'root', '', 'test');
$stmt = $db->stmt_init();
$sql = "SELECT `text` FROM `longtext` WHERE `id` = 1";
$stmt->prepare($sql);
$stmt->execute();
$stmt->bind_result($text);
$stmt->fetch();
$stmt->close();
var_dump(phpversion());
var_dump($db->client_version);
var_dump($db->server_version);
var_dump($db->protocol_version);
var_dump($text);

Output:
string(5) "5.3.0"
int(50137)
int(50137)
int(10)
string(256) "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata "

OS: Win 7

SQL:
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

CREATE DATABASE `test` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `test`;

CREATE TABLE IF NOT EXISTS `longtext` (
  `id` int(11) NOT NULL,
  `text` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO `longtext` (`id`, `text`) VALUES
(1, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.');
 [2009-10-30 15:12 UTC] novitools dot novi at web dot de
So the problem only occurs on specific versions:

No Problem with this Versions:
client_version 50005
server_version 50132

Big Problem with this Versions:
client_version 50137
server_version 50137
 [2009-11-03 09:54 UTC] uw@php.net
Please run you query in the MySQL prompt and show the meta data that is returned from MySQL.  Start the MySQL prompt with "mysql --column-type-info" followed by your usual "-u", "-p", "-h" etc. options.

For example:

nixnutz@ulflinux:~> /usr/local/mysql/bin/mysql   --column-type-info -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.1.39-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select 1;
Field   1:  `1`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     1
Max_length: 1
Decimals:   0
Flags:      NOT_NULL BINARY NUM


+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

But, of course, run your failing query and run mysql prompt on your system.

Thanks,
Ulf



 [2009-11-03 14:33 UTC] novitools dot novi at web dot de
Here is the result:

Field   1:  `You can only read the first 256 words of this text. That
is why I must write such a long text, because I must reach the limit of
256 words. The same error occours, when you try to select a text column
from the database. But I didn't had this error before `
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  latin1_swedish_ci (8)
Length:     284
Max_length: 284
Decimals:   31
Flags:      NOT_NULL


+-------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------+
| You can only read the first 256 words of this text. That
is why I must write such a long text, because I must reach the limit of
256 words. The same error occours, when you try to select a text column
from the database. But I didn't had this error before
    |
+-------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------+
| You can only read the first 256 words of this text. That
is why I must write such a long text, because I must reach the limit of
256 words. The same error occours, when you try to select a text column
from the database. But I didn't had this error before in a previous
version of php. |
+-------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------+
1 row in set (0.00 sec)
 [2009-11-03 21:32 UTC] uw@php.net
Thanks for the feedback!

I feared that meta data would indicate the correct length. To be honest, I have no idea so far what may be causing it.
 [2009-12-22 10:01 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-12-25 19:06 UTC] novitools dot novi at web dot de
I was ill for the last few day. Thats why it took me so long to answer. I tried to use the latest snapshot, but I had problems with a connection to a MySQL-Server. The installation of an apache and PHP itself worked fine, but every access to the MySQL-Server end in an Internal Server Error.

However a new version of XAMPP has been offered since yesterday. The new Version inculdes PHP 5.3.1 . And now it runs. The problem I have described doesn't exists anymore in PHP Version 5.3.1 .
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 13:01:27 2024 UTC