PHP 8.3.4 Released!

pg_lo_create

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

pg_lo_createCrea un large object

Descrizione

pg_lo_create(resource $connessione): int

pg_lo_create() crea un Large Object e restituisce l'oid dello stesso. connessione specifica una connessione valida al database aperta da pg_connect() o pg_pconnect(). I modi di accesso di PostgreSQL INV_READ, INV_WRITE e INV_ARCHIVE non sono supportati, l'oggetto è sempre creato con accesso sia in lettura che in scrittura. INV_ARCHIVE è stato rimosso da PostgreSQL (versioni 6.3 e successive). La funzione restituisce l'oid del large object, altrimenti restituisce false in caso di errore.

Per utilizzare l'interfaccia large object (lo) è necessario includerla in un blocco di transazione.

Nota:

Questa funzione si chiamava pg_locreate().

add a note

User Contributed Notes 1 note

up
0
andrea dot galli at acotel dot com
20 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();
?>
To Top