简体   繁体   English

UPDATE上的TIMESTAMP不适用于PHP

[英]TIMESTAMP on UPDATE doesn't work with PHP

I have a feeddate column with the info below.. 我有一个feeddate列,其中包含以下信息。

type : timestamp 类型:时间戳
attributes : on update CURRENT_TIMESTAMP 属性:更新时CURRENT_TIMESTAMP
default : CURRENT_TIMESTAMP 默认值:CURRENT_TIMESTAMP

and when I used PHP to INSERT INTO the rows with this code .. 当我使用PHP将此代码插入行时..

$badgefeed = "INSERT INTO d VALUES ('','".$userID."','Badge','','".$badgeNAME."','".$badgeTYPE."','".$badgelv."','','')";
$badgefeedQ = mysql_query($badgefeed);

(feeddate is on the last column that NULL) (feeddate在最后一列为NULL的位置)

This feeddate doesn't update and be like 0000-00-00 00:00:00 该feeddate不会更新,并且就像0000-00-00 00:00:00
but it's gonna work when I used PHP to UPDATE something that already had in the table. 但是当我使用PHP 更新表中已有的内容时,它将起作用。

Did I do anything wrong with my feeddate structure or the INSERT code is incorrect ? 我的feeddate结构是否做错了什么,或者INSERT代码不正确?

Your query should be: 您的查询应为:

$badgefeed = "INSERT INTO d VALUES ('','".$userID."','Badge','','".$badgeNAME."','".$badgeTYPE."','".$badgelv."','')";

Don't use any value for the last column as you are using the timestamp as default value in MySQL. 不要在最后一列使用任何值,因为在MySQL中将时间戳用作默认值。 Just omit the last (blank) value from your query. 只需省略查询中的最后一个(空白)值即可。 In such a way, value for the concerned column will be considered null and thus default timesamp will will be used. 这样,相关列的值将被认为是空值,因此将使用默认时间戳。

Insead of '' use null . 欧洲工商管理学院的''使用null
This way, mysql manages the value itself. 这样, mysql自行管理值。

If you specify any value, the server will take your value, regardless other triggers, settings. 如果指定任何值,则服务器将采用您的值,而不考虑其他触发器,设置。

If you don't include the column in the insert statement or leave it blank (null), it will get set by the server, according to the defaults. 如果您未在insert语句中包括该列或将其保留为空白(空),则它将由服务器根据默认设置进行设置。 In this case the default being on update CURRENT_TIMESTAMP 在这种情况下,默认on update CURRENT_TIMESTAMP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM