PHP mysql auto insert timestamp

后端 未结 4 1689
萌比男神i
萌比男神i 2021-02-14 02:32

Say I have a table name auto_parts with these fields. id, part, price, timestamp and I insert a new row via php as so:

$query = \"insert into auto_p         


        
4条回答
  •  暖寄归人
    2021-02-14 02:57

    What you need to do is declare timestamp to be of type in your sql

    timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
    

    and modify the query to

    $query = "insert into auto_parts(id, part, price)
      values(1, 'axle', 200)"
    mysql_query($query);
    

提交回复
热议问题