略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: pg_lo_create

2024-12-22

pg_lo_create

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

pg_lo_create新建一个大型对象

说明

pg_lo_create(resource $connection): int

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

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

注意:

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

add a noteadd a note

User Contributed Notes 1 note

up
0
andrea dot galli at acotel dot com
19 years ago
<?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();
?>

官方地址:https://www.php.net/manual/en/function.pg-lo-create.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3