Swoole\Coroutine\PostgreSQL->fetchArray(...)

Declaration

<?php
Swoole\Coroutine\PostgreSQL->fetchArray(resource $queryResult, int $row, $resultType = SW_PGSQL_BOTH): 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 as an array.

resultType

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

Return

Returns a single row as an array based on the row number and result type.


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.

Return Types

  • SW_PGSQL_BOTH (default): Returns both numerical and associative indices
  • SW_PGSQL_ASSOC: Returns an associative array with the field name as the key index
  • SW_PGSQL_NUM: Return the field number as the key value


Example

<?php

use Swoole\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;');

    $arr = $pg->fetchArray($result, 1, SW_PGSQL_ASSOC);

    var_dump($arr);
});