2

Consider this:

    +---------------+--------------+------+-----+-------------------+-----------------------------+
    | Field         | Type         | Null | Key | Default           | Extra                               |
    +---------------+--------------+------+-----+-------------------+-----------------------------+
    | email_address | varchar(100) | NO   | PRI | NULL              |                             |
    | create_date   | timestamp    | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
    | optin_date    | timestamp    | YES  |     | NULL              |                             |
    | optout_date   | timestamp    | YES  |     | NULL              |                             |
    +---------------+--------------+------+-----+-------------------+-----------------------------+

Using PHP, how can I make the optin_date and optout_date columns store the current timestamp?

4
  • Haven't really tried anything yet. I have this so far: update table set optin_date = now(). Any thoughts? Commented Jan 4, 2012 at 7:51
  • Why do you need to have some 'timestamp on update CURRENT_TIMESTAMP' fields? They will have the SAME values after UPDATE. Commented Jan 4, 2012 at 8:54
  • @Devart What's the correct way? Commented Jan 5, 2012 at 1:49
  • Similar question (see the comments) - stackoverflow.com/questions/5592049/… Commented Jan 5, 2012 at 8:09

1 Answer 1

3

You can have only one current_timestamp column. For the second you have to use trigger on insert/update.

http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.