OpenSwoole\Coroutine\PostgreSQLStatement->execute(...)

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

Declaration

<?php OpenSwoole\Coroutine\PostgreSQLStatement->execute(array $params = []): bool

Parameters

params

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.

Return

Returns true on success. Returns false on failure, check the error and resultDiag properties of the statement.


Description

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.


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=***");

    $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());
    }
});
Last updated on November 20, 2026