PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Iterating over a table (with Zend_Db_Table and Zend_Paginator)

Note: This article was originally published at Planet PHP on 12 October 2011.
Planet PHP

So frequently, I need to run small data migrations or transformations. Especially on the way to Doctrine, there's a lot to clean-up in a database which has been used and evolved over five years or so.

The other day, I wanted to run some transformations on the data located a history column in a pretty simple table - here's what it looks like:

mysql SHOW FIELDS FROM data; +-------------+------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------------------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | first | varchar(255) | YES | MUL | NULL | | | last | varchar(255) | YES | MUL | NULL | | | email | varchar(255) | YES | MUL | NULL | | | history | varchar(255) | YES | MUL | NULL | | | rec_datemod | datetime | YES | | NULL | | | rec_dateadd | datetime | NO | MUL | 0000-00-00 00:00:00 | | +-------------+------------------+------+-----+---------------------+----------------+ 12 rows in set (0.02 sec)

Building a class to interface the table is simple:

Now it should be easy to iterate across it, find data and save - wrong!

... more after the jump.