News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Young's Blog:
Chunking Large Queries with Iterators in PHP
October 07, 2009 @ 10:42:02

Since sometimes you just don't want all of the results of a query back at once, Rob Young has posted a solution of his own using the Iterators included with PHP as a part of the SPL. His solution is to wrap it in a ChunkedQueryIterator that handles the work behind the scenes.

When executing large queries it's usually best not to load the whole result set in one go. Memory isn't infinite and PHP isn't renowned for handling it very well. So the obvious answer is to chunk the large query in to lots of smaller queries. [...] We want something to which we can just provide a PDO object, an SQL query and the chunk size. We should then be able to iterate over the resulting object as though it were a single result set.

He includes two code snippets of it in action, but asks the question of his readers - "How do you handle large database queries?" - to get some feedback on other alternatives.

0 comments voice your opinion now!
chunk large query iterator pdo


blog comments powered by Disqus

Similar Posts

David Coallier's Blog: Zend_Db Without PDO part #3 (SVN Repository)?

Unravel the Music Blog: Partial-page caching with Memcached and PHP in 3 easy steps

DevShed: Working with Prepared Queries with PDO Objects in PHP 5

DevShed: Paginating Database Records with the Code Igniter PHP Framework

Lukas Smith's Blog: Query parameter handling in Symfony2


Community Events





Don't see your event here?
Let us know!


conference developer podcast zendserver release community introduction interview series code symfony language deployment laravel framework list tips threedevsandamaybe development api

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework