#40913 [Com]: PDO::PARAM_LOB does not bind to a stream for fetching a BLOB

[email protected] ("mattgrdinic at yahoo dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
 ID:               40913
 Comment by:       mattgrdinic at yahoo dot com
 Reported By:      dennis at inmarket dot lviv dot ua
 Status:           Assigned
 Bug Type:         PDO related
 Operating System: Win XP
 PHP Version:      5.2.1
 Assigned To:      wez
 New Comment:

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);
	$result_img->fetch(PDO::FETCH_BOUND);
	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.


Previous Comments:
------------------------------------------------------------------------

[2008-06-01 13:00:40] 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 FileData FROM UserFile WHERE ID=?";

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

Expected result:
----------------
resource

Actual result:
--------------
string

------------------------------------------------------------------------

[2008-06-01 12:56:18] 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->execute(array($FileID));
$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:
----------------

------------------------------------------------------------------------

[2007-06-19 19:06:08] 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).

------------------------------------------------------------------------

[2007-03-25 12:29:07] dennis at inmarket dot lviv dot ua

Description:
------------
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->execute();
$stmt->bindColumn(1, $mime);
$stmt->bindColumn(2, $image, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
var_dump($image);

Expected result:
----------------
Resource #1

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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40913&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.