PHP 8.3.0 RC 6 available for testing

pg_lo_open

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

pg_lo_open打开大对象

说明

pg_lo_open(PgSql\Connection $connection, int $oid, string $mode): PgSql\Lob|false

pg_lo_open() 打开数据库中的大对象并返回 PgSql\Lob 实例,以便对其进行操作。

警告

在关闭 PgSql\Lob 实例之前不要关闭数据库连接。

要使用大对象接口,必须将其封装在一个事务块中。

注意:

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

参数

connection

An PgSql\Connection instance. When connection is unspecified, the default connection is used. The default connection is the last connection made by pg_connect() or pg_pconnect().

警告

As of PHP 8.1.0, using the default connection is deprecated.

oid

数据库中大对象的 OID

mode

可以是只读的“r”、只写的“w”或读写的“rw”。

返回值

PgSql\Lob 实例, 或者在失败时返回 false

更新日志

版本 说明
8.1.0 现在返回 PgSql\Lob 实例;之前返回 resource
8.1.0 现在 connection 参数接受 PgSql\Connection 实例,之前接受 resource

示例

示例 #1 pg_lo_open() 示例

<?php
$database
= pg_connect("dbname=jacarta");
pg_query($database, "begin");
$oid = pg_lo_create($database);
echo
"$oid\n";
$handle = pg_lo_open($database, $oid, "w");
echo
"$handle\n";
pg_lo_write($handle, "large object data");
pg_lo_close($handle);
pg_query($database, "commit");
?>

参见

add a note

User Contributed Notes 1 note

up
1
metator at netcabo dot pt
18 years ago
Just for the record, a user must be a superuser (database owner) in order to invoke pg_lo_open() (though pg_lo_create() may be invoked...). This opens a gigantic security hole in the db. If a user is not a superuser, db will raise an error with message "Can't create Large Object.".
Thus, imho, one should use pg_escape_bytea() instead.
To Top