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

Declaration

<?php
Swoole\Coroutine\PostgreSQL->fetchObject(resource $queryResult, int $row): object

Parameters

queryResult

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

row

The row number within the SQL result you want to extract.

Return

Returns a row from the results as an object.


Description

Extracts a single row as an object from the result of a SQL query.


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;');

    $row = 0;
    for($row = 0; $row < $pg->numRows($result); $row++)
    {
        $data = $pg->fetchObject($result, $row);
        echo $data->id . " \n ";
    }
});


<?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;');

    $row = 0;
    while($data = $pg->fetchObject($result, $row))
    {
        echo $data->id . " \n ";
        $row++;
    }
});