PDO LOB Insert Loses Bytes

Bug #137960 reported by cowsandmilk
2
Affects Status Importance Assigned to Milestone
php5 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Binary package hint: php5-mysql

When inserting an 8262 byte image into the database using pdo lobs on ubuntu, only 7966 bytes are inserted. All 8262 bytes are inserted with the same script on windows. Note, debian does the same thing as ubuntu.

Create a mySQL table called files in a database called play with this structure:
CREATE TABLE `files` (
  `fileID` int(10) unsigned NOT NULL auto_increment,
  `type` varchar(50) collate utf8_unicode_ci NOT NULL default '',
  `data` blob NOT NULL,
  PRIMARY KEY (`fileID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Put an image in a web directory.
Put this script in the same directory
<?php

/*this works fine*/
$imagesize = getimagesize('dm color logo copy.gif');
$fp = fopen('dm color logo copy.gif', 'rb');

/**
 * When Ubuntu inserts images into the database using pdo lobs, it cuts them off.
 * This same script works perfectly on Windows.
 * On Ubuntu, a 8262 byte image turns into 7966 bytes in the database
 * On Windows, it is stored with the correct size.
 */
$db = new PDO('mysql:host=localhost;dbname=play', 'db_username', 'db_password', array( PDO::MYSQL_ATTR_INIT_COMMAND=>'SET CHARACTER SET utf8;', PDO::MYSQL_ATTR_MAX_BUFFER_SIZE=>4194304 ) );
$prepared = $db->prepare('INSERT INTO `files` (`type`,`data`) VALUES (:type, :data)');
$prepared->bindParam(':type',$imagesize['mime'], PDO::PARAM_STR, 50);
$prepared->bindParam(':data', $fp, PDO::PARAM_LOB);
$prepared->execute();

/*this works fine*/
$id = $db->lastInsertId();

/*From other tests, this works fine on ubuntu*/
$prepared = $db->prepare('SELECT `type`, `data` FROM `files` WHERE `fileid` = :fileid');
$prepared->bindParam(':fileid',$id, PDO::PARAM_INT);
$prepared->execute();
$prepared->bindColumn(1, $type, PDO::PARAM_STR, 256);
$prepared->bindColumn(2, $lob, PDO::PARAM_LOB);
$prepared->fetch(PDO::FETCH_BOUND);
header("Content-Type: $type");
echo $lob;

?>

This script works on windows. It does not work on Ubuntu Feisty. It also does not work on MediaTemple's Grid Server which runs some version of Debian (which is where I originally discovered the problem).

For examples, see http://cowsandmilk.net/pdolob/pdolobtest.php for running on ubuntu and http://cowsandmilk.homeip.net/pdolob/pdolobtest.php for running on windows. http://sladm.org/pdolob/pdolobtest.php for running on media temple grid server

(or look at http://cowsandmilk.net/pdolob/ubuntuoutput.gif vs. http://cowsandmilk.net/pdolob/windowsoutput.gif vs. http://cowsandmilk.net/pdolob/mediatempleoutput.gif)

See http://php.net/pdo#pdo.lobs for examples on using lobs in pdo

Revision history for this message
cowsandmilk (dhall-wustl) wrote :

I found this also happens on OS X, so submitted to PHP as bug #42588

Revision history for this message
Chuck Short (zulcss) wrote :

If possible can you test this in hardy?

Thanks
chuck

Changed in php5:
status: New → Incomplete
Revision history for this message
cowsandmilk (dhall-wustl) wrote :

tested in hardy alpha-5, same results.

Revision history for this message
cowsandmilk (dhall-wustl) wrote :

I should add that without PDO::MYSQL_ATTR_INIT_COMMAND=>'SET CHARACTER SET utf8; , this does not occur.

Revision history for this message
Russell Smith (mr-russ) wrote :

This is still a problem in hardy with all updates. I've not checked any other versions.

I have updated the php bug with comments to see if it will be looked at further. However due to the nature of the php bug trackers, I'm unable to change the bug status from "No Feedback" to "Open". Hopefully the original reporter will make that change for me.

Also give I'm able to reproduce on hardy, the fact there is a workaround and PHP are accepting there is a problem of some kind I've marked this bug as Confirmed.

Changed in php5:
status: Incomplete → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.