NYCPHP Meetup

NYPHP.org

[nycphp-talk] mysql: timestamp issue?

bzcoder bzcoder at bzcode.com
Wed Jul 2 06:01:31 EDT 2008


Marc Antony Vose wrote:
> Hi there.
>
> I exported this create table statement from an existing table of 
> mine.  I was just wondering if someone would enlighten me as to why my 
> "edi_updated" timestamp column is not auto-updating when a record is 
> updated?

Well, my guess would be because your code tells it not to.  For 
example,  if your using some nice object oriented code, where you do 
something like:
-----
// set some edition id value
$ediid = 123;

// load the edition data
$myedi = new editionClass($ediid);

// set a 20% discount - ideally this data should actually
// have come from someone, ie entered on a form perhaps
// by the user
$discount = .80;
$newprice = $myedi->getField('edi_price') * $discount;

// update the price of the edition
$myedi->setField('edi_price', $newprice);

// update the record
$myedi->update();
----

or if you prefer a condensed coding style:
------
// get the edition
$myedi->new editionClass($ediid);
//set the discount, ideally this is provided by a user instead
// of hardcoded
$discount=.80;
// make our changes and update the record
$myedi->setDiscount($discount)->updateRecord();
------

The above generates a long update clause such as:
UPDATE EDITIONS
SET EDI_TITLE='$this->edi_title',
...
EDI_UPDATED=$this->edi_updated,
...
WHERE EDI_ID = $this->edi_id

(though of course, your using the safer syntax where you bind the 
variables instead of writing it out directly - it's just easier to write 
this way)

In which case, since your code explicitly specified what the update 
timestamp should be(and since you did not change the value, it is the 
original timestamp) the field will not be updated.

Just a guess though, since I don't have your code here. :-)




More information about the talk mailing list