Fix iterator bugs

- Iterator was duplicating first result due to extra data seek. This also causes the last resultset to be lost in iterator mode.
- Since the iterator may throw an error, it needs to have access to both $this->link and $db->dieOnErrors

- In query_factory, $zp_real was incorrectly used where $this->dieOnErrors was required