Re: HTTP Download with Postgresl
| From: | Michael Wallner | Date: | Fri, 16 Jul 2004 09:51:31 +0000 |
| Subject: | Re: HTTP Download with Postgresl | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13723@lists.php.net to get a copy of this message | ||
Hi Jeroen Houben, you wrote:
> Okay I'm starting to to grasp this a bit know. Just to verify: I can
> write a stream wrapper for Postgres large objects so a PG large object
> is treated just as any other stream in PHP. You'll be able to read from
> it, write to it etc etc. in a standardized way. Right?
Yes
> I'll try and find some time to experiment with this.
Look at this dirty example - it's supposed to work but
I don't know why pg_lo_open returns TRUE instead of a
resource...
--- cut ---
$pg_conn = pg_connect('host=localhost user=mike password=');
pg_query($pg_conn, 'begin');
$pg_blob = pg_lo_create($pg_conn);
stream_register_wrapper('pglob', 'Stream_LOB_pgsql');
$f = fopen('pglob://'. $pg_blob, 'w');
fwrite($f, 'huhu');
fclose($f);
$f = fopen('pglob://'. $pg_blob, 'r');
echo fread($f, 4);
fclose($f);
pg_lo_unlink($pg_conn, $pg_blob);
pg_query($pg_conn, 'commit');
class Stream_LOB_pgsql
{
var $lob;
function stream_open($path, $mode)
{
global $pg_conn;
if (!preg_match('/(\d+)/', $path, $matches)) {
return false;
}
list(, $loid) = $matches;
$this->lob = pg_lo_open($pg_conn, $loid, $mode);
return $this->lob;
}
function stream_read($length)
{
return pg_lo_read($this->lob, $length);
}
function stream_write($data)
{
return pg_lo_write($this->lob, $data);
}
function stream_close()
{
return pg_lo_close($this->lob);
}
}
--- cut ---
Regards,
--
Michael - < mike(@)php.net >
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc