Source for file PgLOB.php
Documentation is available at PgLOB.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* @author Michael Wallner <mike@php.net>
* @copyright 2003-2005 Michael Wallner
* @version CVS: $Id: PgLOB.php,v 1.14 2005/11/13 19:18:55 mike Exp $
* @link http://pear.php.net/package/HTTP_Download
$GLOBALS['_HTTP_Download_PgLOB_Connection'] = null;
* PgSQL large object stream interface for HTTP_Download
* require_once 'HTTP/Download.php';
* require_once 'HTTP/Download/PgLOB.php';
* $db = &DB::connect('pgsql://user:pass@host/db');
* // or $db = pg_connect(...);
* $lo = HTTP_Download_PgLOB::open($db, 12345);
* $dl = &new HTTP_Download;
* @version $Revision: 1.14 $
class HTTP_Download_PgLOB
function setConnection ($conn)
if (is_a($conn, 'DB_Common')) {
} elseif ( is_a($conn, 'MDB_Common') ||
is_a($conn, 'MDB2_Driver_Common')) {
$conn = $conn->connection;
$GLOBALS['_HTTP_Download_PgLOB_Connection'] = $conn;
if (is_resource($GLOBALS['_HTTP_Download_PgLOB_Connection'])) {
return $GLOBALS['_HTTP_Download_PgLOB_Connection'];
function open ($conn, $loid, $mode = 'rb')
HTTP_Download_PgLOB ::setConnection ($conn);
return fopen('pglob:///'. $loid, $mode);
* Stream Interface Implementation
function stream_open ($path, $mode)
if (!$this->conn = HTTP_Download_PgLOB ::getConnection ()) {
if (!pg_query ($this->conn, 'BEGIN')) {
$this->handle = pg_lo_open ($this->conn, $this->ID, $mode);
pg_lo_seek ($this->handle, 0 , PGSQL_SEEK_END );
$this->size = (int) pg_lo_tell ($this->handle);
pg_lo_seek ($this->handle, 0 , PGSQL_SEEK_SET );
function stream_read ($length)
return pg_lo_read ($this->handle, $length);
function stream_seek ($offset, $whence = SEEK_SET )
return pg_lo_seek ($this->handle, $offset, $whence);
return pg_lo_tell ($this->handle);
return pg_lo_tell ($this->handle) >= $this->size;
return array ('size' => $this->size, 'ino' => $this->ID);
function stream_write ($data)
return pg_lo_write ($this->handle, $data);
if (pg_lo_close ($this->handle)) {
return pg_query ($this->conn, 'COMMIT');
pg_query ($this->conn ,'ROLLBACK');
Documentation generated on Wed, 31 Oct 2007 03:30:12 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|