silverstripe-postgresql/code/PostgreSQLQuery.php
2018-03-16 16:43:07 +00:00

49 lines
989 B
PHP

<?php
namespace SilverStripe\PostgreSQL;
use SilverStripe\ORM\Connect\Query;
/**
* A result-set from a PostgreSQL database.
*
* @package sapphire
* @subpackage model
*/
class PostgreSQLQuery extends Query
{
/**
* The internal Postgres handle that points to the result set.
* @var resource
*/
private $handle;
/**
* Hook the result-set given into a Query class, suitable for use by sapphire.
* @param resource $handle the internal Postgres handle that is points to the resultset.
*/
public function __construct($handle)
{
$this->handle = $handle;
}
public function __destruct()
{
if (is_resource($this->handle)) {
pg_free_result($this->handle);
}
}
public function getIterator()
{
while ($data = pg_fetch_assoc($this->handle)) {
yield $data;
}
}
public function numRecords()
{
return pg_num_rows($this->handle);
}
}