php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53483 using mysqli_stmt::send_long_data() makes execute() fail
Submitted: 2010-12-06 12:22 UTC Modified: 2011-01-07 15:35 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: squarious at gmail dot com Assigned: mysql (profile)
Status: Not a bug Package: MySQLi related
PHP Version: 5.3.3 OS: linux
Private report: No CVE-ID: None
 [2010-12-06 12:22 UTC] squarious at gmail dot com
Description:
------------
This bug was found from a framework test units after a system upgrade (ubuntu/10.04 -> ubuntu/10.10). The bug was tracked that the send_long_data() stopped working completely. If I try to use it for large packets, the following execute() command will fail with error "Error executing prepared statement. Incorrect arguments to mysqld_stmt_execute".

I made a script that reproduces 100% the bug and I ran it at 
ubuntu/10.04(php5.3.2, mysql5.1.41) PASS,
ubuntu/10.10(php5.3.3, mysql5.1.49) FAIL,
debian/squeeze(php5.3.3, mysql5.1.49) FAIL.

So I assume its a regression at php's 5.3.3.

Test script:
---------------
//Full test @ http://codepad.org/eKnJnWnC 

// Code chunk that trigger the problem.
if (!$stmt->bind_param('b', $null))
	die("Error binding parameters. {$stmt->error}\n");
foreach(str_split($big_data, $max_allowed_packet) as $packet )
	if (!$stmt->send_long_data(0, $packet))
		die("Error sending long packet. {$stmt->error}\n");
if (!$stmt->execute())
	die("Error executing prepared statement. {$stmt->error}\n");

Expected result:
----------------
OK: Executed prepared statement with blob less than max_allowed_packet.
OK: Executed prepared statement with blob bigger than max_allowed_packet, sent at chunks.


Actual result:
--------------
OK: Executed prepared statement with blob less than max_allowed_packet.
Error executing prepared statement. Incorrect arguments to mysqld_stmt_execute

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-08 15:49 UTC] jbreton at kronostechnologies dot com
I am experiencing the same problem, but I'm starting to think it is related to 
MySQL. 

I'm also using php5.3.3 and mysql5.1.49, but colleague is using php5.3.3 and 
mysql5.1.41 and your test passes without any problem.
 [2010-12-08 16:24 UTC] andrey@php.net
Looks a problem because of this MySQL Server bug 
http://bugs.mysql.com/bug.php?id=26824

After trying the script with 5.3.4-dev , libmysql from Ubuntu 9.10 and mysqlnd, and two different MySQL versions 5.1.51 and 5.5.5-m3.

MySQL 5.1
libmysql : 
OK: Executed prepared statement with blob less than max_allowed_packet.
OK: Executed prepared statement with blob bigger than max_allowed_packet, sent at chunks.

myslqnd:
OK: Executed prepared statement with blob less than max_allowed_packet.
and then few errors because of Packet out of order - an error packet interleaving (see the MySQL bug description for more information)

MySQL 5.5
libmysql : 
OK: Executed prepared statement with blob less than max_allowed_packet.
Error executing prepared statement. Incorrect arguments to mysqld_stmt_execute
mysqlnd:
OK: Executed prepared statement with blob less than max_allowed_packet.
Error executing prepared statement. Incorrect arguments to mysqld_stmt_execute

This needs more investigation with wireshark, something changed in the server but in any case there was a problem. Haven't checked with MySQL 5.0, as I don't have one handy.
 [2010-12-20 15:10 UTC] andrey@php.net
with mysqlnd and MySQL 5.5.8 GA

andrey@poohie:~/PHP_5_3$ ./php a.php
OK: Executed prepared statement with blob less than max_allowed_packet.
OK: Executed prepared statement with blob bigger than max_allowed_packet, sent at chunks.

Seems there was a problem in 5.5.5
 [2010-12-20 15:55 UTC] andrey@php.net
mysqlnd with MySQL 5.0.90

andrey@poohie:~/PHP_5_3$ ./php a.php
OK: Executed prepared statement with blob less than max_allowed_packet.
Error executing prepared statement. Got a packet bigger than 'max_allowed_packet' bytes
 [2010-12-20 16:02 UTC] andrey@php.net
libmysql + MySQL 5.0.90
andrey@poohie:~PHP_5_3$ ./php a.php
OK: Executed prepared statement with blob less than max_allowed_packet.
OK: Executed prepared statement with blob bigger than max_allowed_packet, sent at chunks.

libmysql + MySQL 5.5.8
andrey@poohie:~/PHP_5_3$ ./php a.php
OK: Executed prepared statement with blob less than max_allowed_packet.
OK: Executed prepared statement with blob bigger than max_allowed_packet, sent at chunks.
 [2010-12-20 16:50 UTC] andrey@php.net
libmysql + MySQL 5.1.55
andrey@poohie:~/PHP_5_3$ ./php a.php
OK: Executed prepared statement with blob less than max_allowed_packet.
OK: Executed prepared statement with blob bigger than max_allowed_packet, sent at chunks.

mysqlnd + MySQL 5.1.55
andrey@poohie:~/PHP_5_3$ ./php a.php
OK: Executed prepared statement with blob less than max_allowed_packet.
OK: Executed prepared statement with blob bigger than max_allowed_packet, sent at chunks.
 [2010-12-20 16:51 UTC] andrey@php.net
I can't reproduce the problem :(
 [2010-12-20 17:14 UTC] jbreton at kronostechnologes dot com
You haven't tried mysql5.1.49 which was specified in squarious' description.

I just tried with php 5.3.4 stable and mysql5.1.49 without success.
 [2010-12-20 17:14 UTC] jbreton at kronostechnologes dot com
You haven't tried mysql5.1.49 which was specified in squarious' description.

I just tried with php 5.3.4 stable and mysql5.1.49 without success.
 [2010-12-20 17:56 UTC] jbreton at kronostechnologies dot com
I upgraded mysql to 5.1.54 using debian experimental packages and the problem is 
gone.

Hopefully it won't break my ubuntu setup, which was a brand new 10.10 using 
official packages.
 [2011-01-06 14:20 UTC] uw@php.net
Please always add complete test. Never link external sites.

<?php
// Reproduce bug that with send_long_data, execute() fails

// Agjust your settings before execute
$conn = new mysqli(
	'localhost',	// << Server
	'root',			// << Username
	'root',			// << Password
	'test'		// << Schema
);

if (!$conn->query('CREATE TABLE IF NOT EXISTS `test_bug_blob` (`id` integer auto_increment, `data` BLOB, PRIMARY KEY(`id`));'))
	die("Error creating table.\n");

if (!($result = $conn->query('SELECT @@max_allowed_packet')))
	die("Error reading max allowed packet size.\n");
$max_allowed_packet = $result->fetch_array();
$max_allowed_packet = $max_allowed_packet[0];

if (!($stmt = $conn->prepare('INSERT INTO `test_bug_blob` (`data`) VALUES (?)')))
	die("Cannot prepare statement for INSERT. {$conn->error}\n");

// Sent blob smaller than max allowed_packet
$data = str_repeat('0123456789', $max_allowed_packet/20);
if (!$stmt->bind_param('s', $data))
	die("Error binding parameters. {$stmt->error}\n");
if (!$stmt->execute())
	die("Error executing prepared statement. {$stmt->error}\n");
echo "OK: Executed prepared statement with blob less than max_allowed_packet.\n";

// Sent blob bigger than max allowed_packet
$big_data = str_repeat('0123456789', $max_allowed_packet/9);
$null = null;
if (!$stmt->bind_param('b', $null))
	die("Error binding parameters. {$stmt->error}\n");
foreach(str_split($big_data, $max_allowed_packet) as $packet )
	if (!$stmt->send_long_data(0, $packet))
		die("Error sending long packet. {$stmt->error}\n");
if (!$stmt->execute())
	die("Error executing prepared statement. {$stmt->error}\n");
echo "OK: Executed prepared statement with blob bigger than max_allowed_packet, sent at chunks.\n";
 [2011-01-06 14:28 UTC] uw@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2011-01-06 14:28 UTC] uw@php.net
Andrey, 

smells like a server bug fixed in the latest 5.0, 5.1. 5.5 series. Below is mysqlnd @ 64bit @ MySQL 5.1.45. 

Ulf


nixnutz@linux-fuxh:~/php/php-src/branches/PHP_5_3_cta> sapi/cli/php foo.php
array(1) {
  ["client_info"]=>
  string(48) "mysqlnd 5.0.7-dev - 091210 - $Revision: 306939 $"
}
array(1) {
  ["server_info"]=>
  string(12) "5.1.45-debug"
}
OK: Executed prepared statement with blob less than max_allowed_packet.
Error executing prepared statement. Got a packet bigger than 'max_allowed_packet' bytes
 [2011-01-07 15:35 UTC] andrey@php.net
-Status: Assigned +Status: Bogus
 [2011-01-07 15:35 UTC] andrey@php.net
Seems it was a MySQL Server bug which was fixed in 5.5.8 GA and 5.1.5x
 [2013-02-06 22:46 UTC] jared dot williams1 at ntlworld dot com
With 

PHP 5.6.0-dev (cli) (built: Feb  6 2013 19:53:24) 
MySQL 5.6.10

mysqli using mysqlnd. 

The test code in the comment fails.

OK: Executed prepared statement with blob less than max_allowed_packet.
PHP Warning:  Error while sending STMT_SEND_LONG_DATA packet. PID=21455 in 
/home/jared/Development/junk/foo.php on line 43
Error sending long packet. MySQL server has gone away
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 01:01:28 2024 UTC