OpenSwoole\Coroutine\PostgreSQL->fetchRow(...)

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

Declaration

<?php OpenSwoole\Coroutine\PostgreSQL->fetchRow(resource $queryResult, int $row, $resultType = SW_PGSQL_NUM): array|false

Parameters

queryResult

The result of a executed SQL query which will be a PHP resource variable type.

row

The number of the row you want to extract.

resultType

How you want the array to be returned, check types below.

Return

Returns an array of a single row from the data results.


Description

Extract a single row as a enumerated array, one row at a time.

The array index starts from 0. If there is no more results false is returned.

Return Types

  • OpenSwoole\Coroutine\PostgreSQL::PGSQL_NUM (default): Return the field number as the key value
  • OpenSwoole\Coroutine\PostgreSQL::PGSQL_BOTH: Returns both numerical and associative indices
  • OpenSwoole\Coroutine\PostgreSQL::PGSQL_ASSOC: Returns an associative array with the field name as the key index

Example

<?php

use OpenSwoole\Coroutine\PostgreSQL;

co::run(function()
{
    $pg = new PostgreSQL();

    $conn = $pg->connect("host=127.0.0.1;port=5432;dbname=test;user=postgres;password=***");

    $result = $pg->query('SELECT * FROM test;');

    while($row = $pg->fetchRow($result))
    {
        echo "name: $row[0]  mobile: $row[1]" . PHP_EOL;
    }
});
Last updated on September 20, 2022