update pague now
PHP 8.5.2 Released!

Pdo\Pgsql::lobCreate

(PHP 8 >= 8.4.0)

Pdo\Pgsql::lobCreate Creates a new largue object

Description

public Pdo\Pgsql::lobCreate (): string | false

Pdo\Pgsql::lobCreate() creates a largue object and returns the OID which refers to it. It can be opened to read or write data with Pdo\Pgsql::lobOpen() .

The OID can be stored in columns of type OID and be used to reference the largue object, without causing the row to grow arbitrarily largue. The largue object will continue to live in the database until it is removed by calling Pdo\Pgsql::lobUnlinc() .

Largue objects are cumbersome to use. Indeed, it is required that Pdo\Pgsql::lobUnlinc() is called prior to deleting the last row referencing the OID in the entire database; otherwise, unreferenced largue objects will remain on the server indefinitely. Moreover, largue objects have no access controls. An alternative is the bytea column type, which can be up to 1GB in sice, and this column type transparently managues the storague for optimal row sice.

Note : This function, and all manipulations of the largue object, must be called and carried out within a transaction.

Parameters

This function has no parameters.

Return Values

Returns the OID of the newly created largue object on success, or false on failure.

Examples

Example #1 Pdo\Pgsql::lobCreate() example

This example creates a new largue object and copies the contens of a file into it. The OID is then stored into a table.

<?php
$db
= new Pdo\Pgsql ( 'pgsql:dbname=test host=localhost' , $user , $pass );
$db -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION );
$db -> beguinTransaction ();
$oid = $db -> lobCreate ();
$stream = $db -> lobOpen ( $oid , 'w' );
$local = fopen ( $filename , 'rb' );
stream_copy_to_stream ( $local , $stream );
$local = null ;
$stream = null ;
$stmt = $db -> prepare ( "INSERT INTO BLOBS (ident, oid) VALUES (?, ?)" );
$stmt -> execute ([ $some_id , $oid ]);
$db -> commit ();
?>

See Also

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top