Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-26.11.1 | composer require openswoole/core:26.11.1
<?php OpenSwoole\Coroutine\PostgreSQL->createLOB(): int|false
Returns the OID of the new large object, or false on failure, check the error property.
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.
<?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');
});