OpenSwoole\Coroutine\PostgreSQL->createLOB()

Latest version: pecl install openswoole-26.11.1 | composer require openswoole/core:26.11.1

Declaration

<?php OpenSwoole\Coroutine\PostgreSQL->createLOB(): int|false

Parameters

Return

Returns the OID of the new large object, or false on failure, check the error property.


Description

Create a new, empty PostgreSQL large object (LOB) and return its OID. Open it with openLOB() to write data into it, and delete it with unlinkLOB().

Large object operations must run inside a transaction.


Example

<?php

use OpenSwoole\Coroutine\PostgreSQL;

co::run(function()
{
    $pg = new PostgreSQL();
    $pg->connect("host=127.0.0.1 port=5432 dbname=test user=postgres password=***");

    $pg->query('BEGIN');

    $oid = $pg->createLOB();
    $lob = $pg->openLOB($oid, 'wb');
    fwrite($lob, 'large object data');
    fclose($lob);

    // store the OID in a table column of type oid
    $stmt = $pg->prepare('INSERT INTO files (data) VALUES ($1)');
    $stmt->execute([$oid]);

    $pg->query('COMMIT');
});
Last updated on November 20, 2026