views:

340

answers:

1

I need to run a query which will retrieve a huge amount of records.
This means I can't use the ZF wrappers for mysqli, which deep below the hood uses mysqli-store-result. So, is there a wrapper in ZF for using the mysqli mysqli-use-result link text, which will return an Iterator/record-set/resource and not the array with all the results already loaded into the memory, Or do I need to implement it myself?

+3  A: 

First of all, no Zend Framework database adapters make use of ext/mysql. There are adapters for ext/mysqli and ext/pdo_mysql.

In the MySQLi adapter, it always calls mysqli_store_result() (see Zend/Db/Statement/Mysqli.php, near line 250), which means it only supports buffered query results. Zend Framework does not currently support any option to change this, so you could try to edit that line of code yourself to use mysqli_use_result().

In the PDO_MySQL adapter, I believe the default is to use unbuffered queries, since the PDO documentation shows an example of how to use PDO attributes to coerce buffered queries.

Note that regardless of using unbuffered queries, if you call fetchAll() on a database wrapper class, you'll fetch all rows of your huge result set, and probably exceed PHP's memory limit. So instead, you must begin a query and write a loop to fetch rows one at a time.

Bill Karwin