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->fetchArray(?int $row = null, int $result_type = OPENSWOOLE_PGSQL_BOTH): array|false
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.
How the row is returned, see the description.
Returns a row as an array, or false when there are no more rows.
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 indicesOPENSWOOLE_PGSQL_ASSOC: Returns an associative array with the field name as the key indexOPENSWOOLE_PGSQL_NUM: Return the field number as the key value<?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);
});