<?php
$conn = pg_connect("host='127.0.0.1' dbname='test' user='usertest' password='passtest'");
$fp = fopen('logo.gif', "r");
$buffer = fread($fp, filesize('logo.gif'));
fclose($fp);
pg_exec($conn, "begin");
$oid = pg_locreate($conn);
$rs = pg_exec($conn,"INSERT INTO test(tipo, images) VALUES('A1', $oid);");
$handle = pg_loopen ($conn, $oid, "w");
pg_lowrite ($handle, $buffer);
pg_loclose ($handle);
pg_exec($conn, "commit");
$rs = pg_exec($conn, "SELECT images FROM test WHERE tipo = 'A1';");
$row = pg_fetch_row($rs, 0);
pg_exec($conn, "begin");
$loid = pg_loopen($conn, $row[0], "r");
header("Content-type: image/gif");
pg_loreadall($loid);
pg_loclose($loid);
pg_exec ($conn, "commit");
pg_exec($conn, "begin");
$loid = $row[0];
pg_lounlink($conn, $loid);
pg_exec ($conn, "commit");
pg_exec($conn, "DELETE FROM test WHERE tipo = 'A1';");
pg_close();
?>