|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40913 PDO_MYSQL: PDO::PARAM_LOB does not bind to a stream for fetching a BLOB
Submitted: 2007-03-25 12:29 UTC Modified: 2017-02-03 08:44 UTC
Avg. Score:4.7 ± 0.7
Reproduced:179 of 179 (100.0%)
Same Version:17 (9.5%)
Same OS:26 (14.5%)
From: dennis at inmarket dot lviv dot ua Assigned:
Status: Re-Opened Package: PDO MySQL
PHP Version: 7.0.13 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dennis at inmarket dot lviv dot ua
New email:
PHP Version: OS:


 [2007-03-25 12:29 UTC] dennis at inmarket dot lviv dot ua
PDOStatement::bindColumn($idx, $var, PDO::PARAM_LOB) for SELECT query makes $var a string with the BLOB Data rather than a stream, for both MySQL and SQLite.

Reproduce code:
$id = (int)$_REQUEST['book'];
$stmt = $conn->prepare("SELECT coverMime, coverImage FROM books WHERE id=$id");
$stmt->bindColumn(1, $mime);
$stmt->bindColumn(2, $image, PDO::PARAM_LOB);

Expected result:
Resource #1

Actual result:
String(792) {GIF89a...}


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-19 19:06 UTC] hans at velum dot net
I believe this is probably the same issue, but I also notice that using MySQL to simply execute a SQL query which contains BLOB result columns is also returning strings instead of streams.  The difference being that I'm not using bindColumn() and specifying PDO::PARAM_LOB.  I wouldn't expect that I'd need to, since simply performing a standard fetch() works as expected w/ Postgres (and, I believe, Oracle).
 [2008-06-01 12:56 UTC] mail at matya dot hu
I am using PHP 5.2.6 with MySQL 5.0.51b, and the problem is still present.

Reproduce code:

$sql = "SELECT FileName, ContentType, Size, FileData FROM `" . File::getTableName() . "` WHERE ID=?";
$stmt = $this->_DB->prepare($sql);
$stmt->bindColumn(1, $name, PDO::PARAM_STR, 255);
$stmt->bindColumn(2, $type, PDO::PARAM_STR, 255);
$stmt->bindColumn(3, $size, PDO::PARAM_INT);
$stmt->bindColumn(4, $data, PDO::PARAM_LOB);

Expected result:
 [2008-06-01 13:00 UTC] mail at matya dot hu
I am using PHP 5.2.6 with MySQL 5.0.51b, and the problem is still

Reproduce code:

$sql = "SELECT FileData FROM UserFile WHERE ID=?";

$stmt = $DB->prepare($sql);
$stmt->bindColumn(1, $data, PDO::PARAM_LOB);
echo gettype($data);

Expected result:

Actual result:
 [2008-08-11 17:06 UTC] mattgrdinic at yahoo dot com
Can verify this with PDO->mssql using 5.2.6 and Windows Server 2003. 

// Reproduction code:
$VIN = $_GET['VIN'];
	$imageUrl = $_GET['ImageUrl'];
	$sql_img = "SELECT VIN, Image, ImageUrl FROM ImagesDemo WHERE VIN = :VIN AND ImageUrl =  :imageUrl";
	$result_img = Database::pdo_prepare_query($sql_img, array(':VIN' => $VIN, ':imageUrl' => $imageUrl));
	$result_img->bindColumn('Image', $lob, PDO::PARAM_LOB);
	header("Content-type: image/pjpeg");
        var_dump($lob); // string(4096) + raw image data
	fpassthru($lob); // this call fails with 'supplied argument is not a valid stream resource'
	echo $lob; // this call only spits out 4096 bytes, chopping the image off

End result -- unable to use pdo for blobs.
 [2008-09-30 16:27 UTC] ralfbecker at egroupware dot org
I can reproduce this bug with php5.2.6 on OpenSUSE 11.0

 [2009-04-25 14:44 UTC]
Please try using this CVS snapshot:
For Windows:

 [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".
 [2009-05-29 14:25 UTC] linuxuser586 at yahoo dot com
Problem still exists on Windows 2003 with PHP Version 5.2.10RC2-dev Build Date May 29 2009 11:39:28
 [2009-06-30 14:13 UTC] ralfbecker at egroupware dot org
I still can reproduce the Problem with php5.3.0RC2.
 [2009-07-27 15:12 UTC] ralph dot reckert at web dot de
That error still does not seem to be solved in the current PHP version 5.3.0 nor in 5.2.10. At least it is not listed in the ChangeLog list of fixed bugs of that versions. 

It would be nice if, four years after PDO was released and almost two and a half years after that bug was first reported, someone could try to fix it, really test that fix and make shure it finds it's way into some release version of PHP. 

Until then, in my opinion the status of this bug report should be OPEN!

Best regards,
 [2010-02-19 21:02 UTC] jcook at macmillanmarketing dot com
I've just been able to reproduce this bug today running PHP 5.3.1 on 

Reproduce Code:

$db = db::getConn();
$st = $db->prepare($sql);
$st->execute(array(':id' => $id));
$st->bindColumn(1, $image, PDO::PARAM_LOB);
header ('Content-type: image/jpeg');
fpassthru($image);// this call fails with 'supplied argument is not a
valid stream resource'

Expected result:

Actual result:

I can work around this error for what I'm trying to do but it would be 
nice if this was fixed.
 [2010-08-24 11:22 UTC] david at futuresbright dot com
I have experienced the same issue with Windows 2003 using SQL Server 9.0 and php 5.2.13.

Really disappointing that this bug can have been around for so many years without being fixed.
 [2010-10-05 17:14 UTC] samuel at ingessons dot se
Is there a way to solve the problem and get a stream?
I want to make a pipeline directly from a longblob to the client.
 [2010-10-05 17:23 UTC] samuel at ingessons dot se
The reason why I want to have a stream and not echo it directly is that I use a function that should return a stream.
 [2010-10-05 18:10 UTC] samuel at ingessons dot se
And another reason why I need a stream and not a string is that a string would consume all the memory for a large object.
 [2010-11-06 01:50 UTC]
-Assigned To: wez +Assigned To: mysql
 [2010-11-22 10:43 UTC]
-Status: Verified +Status: Feedback
 [2010-11-22 10:43 UTC]
5.2 only gets security fixes, if at all. 

Can this be reproduced with 5.3.4-RC, using libmysql (recent one!), using mysqlnd?
 [2010-12-27 01:02 UTC] php at paloch dot net
Seems to be fixed in 5.3.4 final. I was struggling with this issue (and PHP 5.2.16) all evening before finding this post. I tried installing PHP 5.3.4 and voila, problem solved.
 [2011-01-04 13:21 UTC]
-Status: Feedback +Status: Closed
 [2011-01-04 13:21 UTC]
See last comment, works with 5.3.4
 [2011-10-20 09:48 UTC] oridan82 at gmail dot com
PHP 5.3.5
PARAM_LOB is returning a string instead of a stream.

$stmt = $conn->prepare($qry);
$stmt->bindValue(1, $_GET['id']);
$stmt->bindValue(2, $_GET['aid']);

$stmt->bindColumn(4, $mimeType, PDO::PARAM_STR, 256);
$stmt->bindColumn(6, $lob, PDO::PARAM_LOB);

echo gettype($lob);

Expected Result:

Actual Result:
 [2012-08-04 12:40 UTC] david dot palella at gmail dot com
The problem is still present with PHP v. 5.3.10 and Ubuntu 12.10
 [2012-11-07 08:55 UTC] vicrry at yahoo dot com dot hk
As of PHP 5.3.15, this bug still exists.
 [2012-11-07 12:15 UTC]
The implementation for this is broken in PDO core. For PGSQL there is a workaround documented:

    Since information about the columns is not always
    available to PDO until the statement is executed,
    portable applications should call this function after 

    However, to be able to bind a LOB column as a stream
    when using the PgSQL driver, applications should call
    this method before calling PDOStatement::execute(),
    otherwise the large object OID will be returned as an integer.

This works neither works with sqlite nor mysql drivers. After research I assume it won't work with other drivers either. The LOB-handling happens in the param_hook for PDO_PARAM_EVT_EXEC_PRE. But this event only happens if there are bound parameters during execute.
But result columns are bound after execute ...

The support for this feature has do be redesigned in PDO core ... as MySQL has no native stream support I don't support adding a hack for this.
 [2012-11-07 12:15 UTC]
-Status: Closed +Status: Re-Opened
 [2012-11-07 12:19 UTC]
-Assigned To: mysql +Assigned To:
 [2013-05-31 05:25 UTC]
PGSQL binds to a stream object for a LOB. Which PDO driver is this referring to?
 [2013-06-12 04:33 UTC]
-Summary: PDO::PARAM_LOB does not bind to a stream for fetching a BLOB +Summary: PDO_MYSQL: PDO::PARAM_LOB does not bind to a stream for fetching a BLOB
 [2014-01-01 12:53 UTC]
-Package: PDO related +Package: PDO MySQL
 [2014-01-24 09:52 UTC] heruan at aldu dot net
Still present in PHP 5.4.9
 [2014-03-19 13:13 UTC] romanoaugusto88 at gmail dot com
Still in PHP 5.5.9
 [2014-03-27 22:16 UTC] benjamin dot morel at strictcoding dot co dot uk
This must be the oldest unsolved PHP bug: 7 years!
Still broken with PHP 5.5.10.

Could a lead developer comment on this please?
 [2014-10-09 09:33 UTC] b27296 at trbvm dot com
Bug is still present in 5.5.17
 [2014-12-03 18:08 UTC] brian at idltg dot in
This is still an issue with PHP 5.5.9 with MS SQL Server 2008 R2. Result is a string instead of a stream.
 [2015-05-09 22:49 UTC] markus at malkusch dot de
Well, it's 2015 now and still present in PHP-5.6.5.
 [2016-03-08 11:36 UTC] joshua at paddle dot com
It's now 2016, and I'm using PHP 5.6.18, and this issue is STILL present. I wonder if it's been fixed in php 7...
 [2016-03-08 12:39 UTC] benjamin dot morel at gmail dot com
Still the same with PHP 7.0.4 and pdo_mysql. It returns a string instead of a resource.

PHP 7 would have been THE opportunity to fix weird behaviours such as this one. Missed again.

It's been 9 years now, since this bug has been open. Maybe we can wait for another 5 years before PHP 8 is released, and this bug can be fixed. Or not.

The fear to break backwards compatibility is SO enormous within the PHP community, that everyone prefers to carry on with bugs, rather than fixing them, so that bad code can continue working from one version to the other. Even major releases.
 [2017-02-03 08:44 UTC]
-Operating System: Win XP +Operating System: -PHP Version: 5.2.6 +PHP Version: 7.0.13
 [2018-04-11 13:54 UTC] samuel dot chemla at orange dot com
it seems this bug won't be fixed soon.
Could you please at least update the doc to reflect that it is broken?
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC