if ($this->data = pg_fetch_assoc($this->result)) {
            $this->valid = true;
            $this->key += 1;
        } else {
            $this->valid = false;
        }
    }
    public function valid()
    {
        return $this->valid;
    }
}
//implementation
$qi = new QueryIterator("usersDB", "user1", "password1");
$qi->execute("select name, email from users");
while ($qi->valid()) {
    print_r($qi->current());
    $qi->next();
}
/* example output

Array
(
    [name] => Afif
    [email] => mayflower@phpxperts.net
)

Array
(
    [name] => Ayesha
    [email] => florence@phpxperts.net