note 85945 added to function.pdo-pgsqllobopen
| From: | knl at bitflop dot com | Date: | Thu, 25 Sep 2008 22:20:35 +0000 |
| Subject: | note 85945 added to function.pdo-pgsqllobopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144712@lists.php.net to get a copy of this message | ||
The above example is missing some data. After spending several hours trying to get it to work in
vain, Jeff Davis from the PostgreSQL channel on IRC (freenode) figured out what was missing.
The below example will work, but you have to insert the MIME type and file size of the large object
that you are storing, so you can use that data for extraction.
<?php
$db = new PDO('pgsql:dbname=test host=localhost', $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->beginTransaction();
$stmt = $db->prepare("SELECT oid, blob_type, filesize FROM BLOBS WHERE ident = ?");
$stmt->execute(array($some_id));
$stmt->bindColumn('oid', $lob, PDO::PARAM_LOB);
$stmt->bindColumn('blob_type', $blob_type, PDO::PARAM_STR);
$stmt->bindColumn('filesize', $filesize, PDO::PARAM_STR);
$stmt->fetch(PDO::FETCH_BOUND);
$stream = $pdo->pgsqlLOBOpen($lob, 'r');
$data = fread($stream, $filesize);
header("Content-type: $blob_type");
echo $data;
?>
Also fpassthru() will just give this result: Warning: fpassthru(): supplied argument is not a valid
stream resource in ...
Use echo or print instead.
----
Server IP: 87.54.44.10
Probable Submitter: 85.233.228.239
----
Manual Page -- http://www.php.net/manual/en/function.pdo-pgsqllobopen.php
Edit -- https://master.php.net/note/edit/85945
Del: integrated -- https://master.php.net/note/delete/85945/integrated
Del: useless -- https://master.php.net/note/delete/85945/useless
Del: bad code -- https://master.php.net/note/delete/85945/bad+code
Del: spam -- https://master.php.net/note/delete/85945/spam
Del: non-english -- https://master.php.net/note/delete/85945/non-english
Del: in docs -- https://master.php.net/note/delete/85945/in+docs
Del: other reasons-- https://master.php.net/note/delete/85945
Reject -- https://master.php.net/note/reject/85945
Search -- https://master.php.net/manage/user-notes.php