> -----Original Message-----
> From: Jack Sleight [mailto:[EMAIL PROTECTED] 
> 
> My second question is does Zend_Db_Table have any built in 
> facility for automatically setting date_created and 
> date_modified fields in the table, and if so how do I 
> configure this. If not, is it easy enough to add myself? I 
> want something that's pretty much automated.

You can do this in your concrete table class, for example:

class MyTable extends Zend_Db_Table_Abstract
{

  public function insert(array $data)
  {
    $date = Zend_Date::now();
    $data['date_created'] = $data['date_modified'] = $date->getIso();
    parent::insert($data);
  }

  public function update(array $data)
  {
    $date = Zend_Date::now();
    $data['date_modified'] = $date->getIso();
    parent::update($data);
  }

}

But this only takes effect if changes are apply through your PHP
application.  If your values are enforced only in your PHP app, then
they may become incorrect for example if someone uses phpMyAdmin to make
a change.

Another alternative is to enforce the date_created and date_modified
values in database triggers.  This means the values are enforced even if
someone makes a change through another client interface.  

If you use MySQL, you can also use their special declarative properties
of the TIMESTAMP datatype.  See
http://dev.mysql.com/doc/refman/5.0/en/timestamp.html:

CREATE TABLE mytable (
  date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, // default on
creation, but no auto-update
  date_modified TIMESTAMP // implicit default on creation and
auto-update
);

Regards,
Bill Karwin 

Reply via email to