When query is executed by Connection or PDO, it will return an object that can stream results back to you. The PDO class execution produces a PDOStatement object which you can iterate over.

If you are using a custom connection, you then will also need a custom object for streaming results.

The only requirement for such an object is that it has to be a Generator. In most cases developers will expect your generator to return sequence of id=>hash representing a key/value result set.

write more