pg_lo_create

(PHP 4 >= 4.2.0, PHP 5, PHP 7)

pg_lo_create新建一个大型对象

说明

int pg_lo_create ( resource $connection )

pg_lo_create() 新建一个大型对象并返回该大型对象的 oidconnection 指定了由 pg_connect()pg_pconnect() 打开的有效的数据库连接号。不支持 PostgreSQL 访问模式 INV_READ,INV_WRITE 和 INV_ARCHIVE,该对象总是以读写方式访问。INV_ARCHIVE 已经从 PostgreSQL 中删除了(6.3 及以上版本)。本函数返回大型对象的 oid,如果出错则返回 FALSE

要使用大型对象(lo)接口,需要将其放置在事务块中。

Note:

本函数以前的名字为 pg_locreate()

User Contributed Notes

andrea dot galli at acotel dot com 05-May-2003 07:21
<?php
// --------- OPEN CONN ---

  
$conn = pg_connect("host='127.0.0.1' dbname='test' user='usertest' password='passtest'");

// --------- OPEN FILE ---

  
$fp = fopen('logo.gif', "r");
  
$buffer = fread($fp, filesize('logo.gif'));
  
fclose($fp);

// --------- CREATE - INSERT OID ---

  
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");

// --------- OPEN - INSERT OID ---

  
$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");

// --------- UNLINK OID ---

  
pg_exec($conn, "begin");

  
$loid = $row[0];
  
pg_lounlink($conn, $loid);

  
pg_exec ($conn, "commit");

// --------- DELETE OID ---

  
pg_exec($conn, "DELETE FROM test WHERE tipo = 'A1';");

// --------- CLOSE CONN ---

  
pg_close();
?>