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).(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
pg_lo_write — Scrive in un large object
pg_lo_write() scrive dati in un large object alla posizione corrente.
Per utilizzare l'interfaccia dei large object, è necessario racchiuderla all'interno di un blocco di transazione.
Nota:
Questa funzione si chiamava pg_lowrite().
lobUn'istanza di PgSql\Lob, restituita da pg_lo_open().
data
I dati da scrivere nel large object. Se length è
un int ed è minore della lunghezza di data, verranno scritti
solo length byte.
length
Un numero massimo opzionale di byte da scrivere. Deve essere maggiore di zero
e non superiore alla lunghezza di data. Il valore predefinito è
la lunghezza di data.
Il numero di byte scritti nel large object, o false in caso di errore.
| Versione | Descrizione |
|---|---|
| 8.1.0 |
Il parametro lob ora si aspetta un'istanza di PgSql\Lob;
in precedenza, era attesa una resource.
|
| 8.0.0 |
length ora è nullable.
|
Example #1 Esempio di pg_lo_write()
<?php
$doc_oid = 189762345;
$data = "Questo sovrascriverà l'inizio del 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");
?>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).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.