News Feed
Jobs Feed
Sections




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

SitePoint PHP Blog:
Sophisticated Object Iterators in PHP
May 05, 2011 @ 12:54:59

Following up on their earlier simple object iterators post, the SitePoint PHP blog is back with a look at more sophisticated iterators you can use to work with database record objects.

In my previous post, Simple Object Iterators in PHP, we discovered how to iterate over array items defined within an object using a foreach loop. However, what if you need to iterate over items which are not stored in an array, e.g. records from a database or lines of text read from a file?

He shows how to create a script that pulls in the users from a database object (PDO, in this case) and implements the Countable and Iterator interfaces. These interfaces give it some special methods that can give counts of the results and help you iterate through the results - current, rewind, next and valid.

0 comments voice your opinion now!
object iterator spl database result pdo countable implement


blog comments powered by Disqus

Similar Posts

WeberDev.com: PHP 101 (part 14): Going To The Polls

Evan Coury's Blog: Using Zend\Dbs TableGateway & HydratingResultSet to return rows as custom enties

PHP Thinktank Blog: SPL and php.NET (phalanger) IRC logs

Brian Swan's Blog: BACKUP and RESTORE A Database with the SQL Server Driver for PHP

Chris Shiflett\'s Blog: PHP and Scalability (Again)


Community Events











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


framework facebook security introduction symfony2 performance hack support component composer podcast install opinion language package application release hhvm unittest database

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