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\PostgreSQLStatement->execute(array $params = []): bool
The values for the $1, $2, ... placeholders, in order. null is sent as SQL NULL, other values are converted to strings. A stream resource is read and its content is sent, a large object stream from openLOB() is sent as its OID.
Returns true on success. Returns false on failure, check the error and resultDiag properties of the statement.
Execute a statement created by PostgreSQL->prepare() with the given parameters. After a successful call the result rows are read from the same statement object with the fetch methods, and the internal row cursor is reset to the first row.
<?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=***");
$stmt = $pg->prepare('INSERT INTO test (id, text) VALUES ($1, $2) RETURNING id');
foreach ([[1, 'one'], [2, 'two'], [3, null]] as $values) {
if (!$stmt->execute($values)) {
var_dump($stmt->error);
break;
}
var_dump($stmt->fetchAssoc());
}
});