Re: explicitly setting timestamps in DataObject
| From: | Justin Patrin | Date: | Wed, 23 Feb 2005 23:50:36 +0000 |
| Subject: | Re: explicitly setting timestamps in DataObject | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-17661@lists.php.net to get a copy of this message | ||
On Wed, 23 Feb 2005 15:35:18 -0800, Sasha Sklar
<Sasha.Sklar@craveonline.com> wrote:
> Hey, I had good success with this board last time, so I thought I'd try
> again. This time I spent a lot more time reading through documentation
> and code before posting.
>
> I have a table with 2 timestamp fields, modified_on and created_on.
> Following the documentation for the version of mysql I'm using,
> modified_on should be updated every time the row is updated, and
> created_on should be left alone unless explicitly set.
>
> My idea was to set created_on explicity in the overloaded insert()
> method for the DataObject class. So I put the statement:
>
> $this->created_on = date('Ymdhis');
>
> in the insert statement before called parent::insert(). And it totally
> didn't work.
>
> At first I thought I had screwed up the format of the timestamp. But
> when I set debug to 5, I saw this:
>
> INSERT INTO comment (comment_comment_type , comment_comment_status ,
> comment_user_id , comment_item_id , comment_title , comment_body )
> VALUES ( 3 , 1 , 2548 , 21 , 'analogically umm twitched kneeled walking
> after iguana' , 'Hello, that pill bug is much more archaic than some
> flirtatious woodchuck. Jeez, the effective krill ' )
>
> The insert statement is not including created_by. But when I output the
> member var before and after the insert, it shows as being there.
>
> Any clues?
>
Yep. DB_DataObject refuses to update timestamps as they're *supposed*
to be updated by the DB itself. First of all, I would suggest using a
different column type (datetime) as mysql timstamps are difficult to
deal with. Second, if you want to keep the monidied_on timestamp I
would suggest changing the created_on field to a datetime and set it
manually. Note that this is all real simple to do by overloading
insert() and update() methods in your DO to set these fields
automatically.
--
Justin Patrin