How do add date and time stamp to an INSERT via PHP with mySQL?

前端 未结 4 1749
感动是毒
感动是毒 2021-01-24 18:38

I have an insert script with mySQL. I need to place the date and time when the record is created in the \'add_time\" column.

Can anyone show me how to modify my existin

4条回答
  •  春和景丽
    2021-01-24 19:11

    You do not need to insert data to that column from PHP at all:

    TIMESTAMP and DATETIME columns can be automatically initializated and updated to the current date and time (that is, the current timestamp).

    So change the add_time column definition to

    add_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    

    and then it will automatically populate the column for you when you insert a new row

    See: MySql Manual on Timestamp Initializations

提交回复
热议问题