Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Coroutine\PostgreSQL->fetchObject(resource $queryResult, int $row): object
The result of a executed SQL query which will be a PHP resource variable type.
The row number within the SQL result you want to extract.
Returns a row from the results as an object.
Extracts a single row as an object from the result of a SQL query.
<?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++;
}
});