Pdo\Pgsql::lobOpen
(PHP 8 >= 8.4.0)
Opens an existing large object stream
Description
Pdo\Pgsql::lobOpen opens a stream to access the data referenced by oid. All usual filesystem functions, such as fread(), fwrite() or fgets() can be used to manipulate the contents of the stream.
Parameters
oidA large object identifier.
modeThe access mode. If
modecontainswor+, the stream is opened for reading and writing; otherwise it is opened for reading only. Ab(binary) flag has no effect. The default"rb"opens the stream for reading.
Return Values
Returns a stream resource on success,Falseforfailure.
Examples
Pdo\Pgsql::lobOpen example
Following on from the Pdo\Pgsql::lobCreate example, this code snippet retrieves the large object from the database and outputs it to the browser.
<?php
$db = new Pdo\Pgsql('pgsql:dbname=test host=localhost', $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->beginTransaction();
$stmt = $db->prepare("SELECT oid FROM BLOBS WHERE ident = ?");
$stmt->execute([$some_id]);
$stmt->bindColumn('oid', $oid, PDO::PARAM_STR);
$stmt->fetch(PDO::FETCH_BOUND);
$stream = $db->lobOpen($oid, 'r');
header("Content-type: application/octet-stream");
fpassthru($stream);
?>See Also
Pdo\Pgsql::lobCreatePdo\Pgsql::lobUnlinkpg_lo_create()pg_lo_open()