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

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

Declaration

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

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

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

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