php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42588 PDO LOB Insert Loses Bytes
Submitted: 2007-09-07 15:29 UTC Modified: 2009-05-03 01:00 UTC
Votes:4
Avg. Score:3.8 ± 1.6
Reproduced:4 of 4 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (50.0%)
From: dhall at wustl dot edu Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5CVS-2007-09-07 (snap) OS:
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dhall at wustl dot edu
New email:
PHP Version: OS:

 

 [2007-09-07 15:29 UTC] dhall at wustl dot edu
Description:
------------
See Ubuntu Bug 137960
I have duplicated this compiling on Mac OS X with the latest CVS snapshot, so I think its not a Debian/Ubuntu packaging bug.

Reproduce code:
---------------
<?php
$imagesize = getimagesize('dm color logo copy.gif');
$fp = fopen('dm color logo copy.gif', 'rb');

/**
 * On Linux/OS X, 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();

$id = $db->lastInsertId();

$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;
?>

Expected result:
----------------
properly output image as on http://cowsandmilk.homeip.net/pdolob/pdolobtest.php

Actual result:
--------------
image missing bytes as on http://cowsandmilk.net/pdolob/pdolobtest.php (goes from 8262 bytes to 7966 bytes)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-07 15:43 UTC] dhall at wustl dot edu
PS.
If you remove the SET CHARACTER SET UTF-8 stuff, it works.  I don't see why that should screw up pdo sending in lobs though.
 [2008-07-14 13:11 UTC] s dot urbanovski at ac-nancy-metz dot fr
Same problem on Debian Lenny (PHP 5.2.6-2).
I'm unable to insert LOB data if I'm using the utf-8 encoding (SET CHARACTER SET utf8; ). Some caracters are converted to 0x3F.
 [2008-09-15 13:28 UTC] johannes@php.net
I guess you're using emulated Prepared Statments, in that case PDO will try to inject the binary data in the query, sett PDO::ATT_EMULATE_PREPARES to false.

(it works with latin charsets since they ore 8byte charsets, whereas utf-8 is multibyte)
 [2008-11-17 09:44 UTC] mr-russ at pws dot com dot au
Adding the suggested parameter makes no different, the selected output is still smaller than the input.

The following are the options I had added to the connection;
array( PDO::ATTR_EMULATE_PREPARES => false, PDO::MYSQL_ATTR_INIT_COMMAND=>'SET CHARACTER SET utf8;', PDO::MYSQL_ATTR_MAX_BUFFER_SIZE=>4194304 )

The octet_length in the mysql cli returns the incorrect value.  So it's the insert side that is having problems.

Adding PDO::MYSQL_ATTR_DIRECT_QUERY=>true to the constant list does not help either.
 [2009-04-25 14:49 UTC] jani@php.net
Please try using this CVS snapshot:

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

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


 [2009-05-03 01:00 UTC] 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".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 23:01:36 2025 UTC