Thanks Bill,
That will work perfectly. I'll probably just stick with the PHP implementation, I'm not worried about direct DB access, as the data is only relevant to people logged into the site anyway.

Thanks again,

Bill Karwin wrote:

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

--
Jack

Reply via email to