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

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

Declaration

<?php OpenSwoole\Coroutine\PostgreSQLStatement->fetchArray(?int $row = null, int $result_type = OPENSWOOLE_PGSQL_BOTH): array|false

Parameters

row

Row number to fetch, starting from 0, the internal row cursor is moved to this row. When null the next row of the internal row cursor is returned.

result_type

How the row is returned, see the description.

Return

Returns a row as an array, or false when there are no more rows.


Description

Extract a single row as an array.

The row count starts from 0. Returns false when there is no more rows to extract or you get to the end.

Result Types

  • OPENSWOOLE_PGSQL_BOTH (default): Returns both numerical and associative indices
  • OPENSWOOLE_PGSQL_ASSOC: Returns an associative array with the field name as the key index
  • OPENSWOOLE_PGSQL_NUM: Return the field number as the key value

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->query('SELECT * FROM test;');

    // the second row (row 1) as an associative array
    $arr = $stmt->fetchArray(1, OPENSWOOLE_PGSQL_ASSOC);

    var_dump($arr);
});
Last updated on November 20, 2026