pg_lo_write

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

pg_lo_writeEscribe un objeto de gran tamaño de PostgreSQL

Descripción

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

pg_lo_write() escribe datos dentro de un objeto de gran tamaño en la posición actual.

Para manipular un objeto de gran tamaño (lo), es necesario colocar las operaciones dentro de un bloque de transacción.

Nota:

Anteriormente, esta función se llamaba pg_lowrite().

Parámetros

lob

An PgSql\Lob instance, returned by pg_lo_open().

data

Los datos a ser escritos en el objeto de gran tamaño. Si length es un int y es inferior al tamaño de data, solo los primeros length bytes serán escritos.

length

Un número máximo de bytes a escribir. Debe ser superior a cero y menor al tamaño de data. Este argumento es opcional; si se omite, tomará por defecto el tamaño de data.

Valores devueltos

El número de bytes escritos en el objeto de gran tamaño o false en caso de error.

Historial de cambios

Versión Descripción
8.1.0 The lob parameter expects an PgSql\Lob instance now; previously, a recurso was expected.
8.0.0 connection es ahora nullable.

Ejemplos

Ejemplo #1 Ejemplo con pg_lo_write()

<?php
$doc_oid
= 189762345;
$data = "Esto sobrescribirá el inicio del objeto de gran tamaño.";
$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");
?>

Ver también

add a note

User Contributed Notes 2 notes

up
0
cedric at isoca.com
24 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
22 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