Thoughts by Techxplorer

Thoughts on my experiences with technology

Using timestamp Fields in MySQL with Lithium

By: Toni Verdú Carbó

This post is a continuation of the series of posts that I’ve written on my experiences with the Lithium framework.

In the MARQues project I wanted to have a very simple way of logging the occurrence of various activities. The two activities I’m most interested in are the two types of searching that a user can undertake. I want the system to be able log when a search is undertaken and what search terms were used.

Initially I’d developed my simple activity logging table in the MySQL database with a timestamp field. Unfortunately this field doesn’t currently work with the Lithium framework. No matter what I did the field was always populated with zeros. This is a known issue and is currently marked as an enhancement.

To resolve the issue I changed the field to an ordinary datetime field and used the PHP date function to populate it. For example I use the model like this:


// build an array of values
$log = array(
  'type'  => 'search',
  'notes' => $this->request->data['search'],
  'timestamp' => date('Y-m-d H:i:s')
);

// create an instance of the model using the values
$activity = ActivityLogs::create($log);

// save the model
$activity->save();

I hope this post proves useful to other who may be experiencing similar issues.

The photo “The passage of Time” was uploaded to Flickr by Toni Verdú Carbó and used under the terms of a Creative Commons License.

Category: Thoughts
Tag: , ,