|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-03-25 12:29 UTC] 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...}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
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.I've just been able to reproduce this bug today running PHP 5.3.1 on Windows. Reproduce Code: $db = db::getConn(); $st = $db->prepare($sql); $st->execute(array(':id' => $id)); $st->bindColumn(1, $image, PDO::PARAM_LOB); $st->fetch(PDO::FETCH_BOUND); header ('Content-type: image/jpeg'); fpassthru($image);// this call fails with 'supplied argument is not a valid stream resource' Expected result: Resource Actual result: string I can work around this error for what I'm trying to do but it would be nice if this was fixed.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 PDOStatement::execute(). 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. http://www.php.net/manual/en/pdostatement.bindcolumn.php 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.