pg_lo_write

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

pg_lo_write向大对象写入数据

说明

pg_lo_write(PgSql\Lob $lob, string $data, ?int $length = null): int|false

pg_lo_write() 在大对象的当前位置写入数据。

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

注意:

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

参数

lob

通过 pg_lo_open() 返回的 PgSql\Lob 实例。

data

写入到大对象中的数据。如果 lengthint 并且少于 data 的长度,仅会写入 length 个字节。

length

可选的最大写入字节数。必须大于零且不大于 data 的长度。默认为 data 的长度。

返回值

写入到大对象的字节数,或出错时为 false

更新日志

版本 说明
8.1.0 现在 lob 接受 PgSql\Lob 实例,之前接受 resource
8.0.0 length 现在可为 null。

示例

示例 #1 pg_lo_write() 示例

<?php
$doc_oid
= 189762345;
$data = "This will overwrite the start of the large object.";
$database = pg_connect("dbname=jacarta");
pg_query($database, "begin");
$handle = pg_lo_open($database, $doc_oid, "w");
$data = pg_lo_write($handle, $data);
pg_query($database, "commit");
?>

参见

add a note

User Contributed Notes 2 notes

up
0
cedric at isoca.com
23 years ago
Be aware when you modify a lo with pg_lowrite() to remove first the old one : if the new lo is smaller than the one before, it only overwrite the begining and you keep the end of the old lo (open with "w" parameter, PHP 4.04 Linux RH).
up
-1
nandrews at logictree dot co dot uk
21 years ago
Using php 4.3.0 and PostgreSQL 7.3.1

I can write a simple script in which pg_lo_write seems to always return 1 and not the number of bytes written, as evidenced by extracting the data through another means.

Further more, I can make this pg_lo_write fail, or at least fail to write all the data it's pretty difficult to tell without the number of bytes written being returned, and not return the false value. In addition to this, the lo resource has been adjusted so that the oid it contains is 0.

Unfortunately, I do not know what exactly the failure mode is, it does seem to be in the ip network communication side of PostgreSQL, which is odd since the unix domain comms works fine for this. However, it would have been useful to have the pg_lo_write() function return as advertised, it would have saved some of the 2 man hours me and the dev. team put into diagnosing this problem.
To Top