[英]How can I update field defined as date in phpmyadmin with current date every time I execute a query in my web page?
I have added a query in my website php page. 我在我的网站php页面中添加了一个查询。 It looks like something... 看起来像......
mysql_select_db("my_db", $con);
$sq2="INSERT INTO querylog(QueryID, Module, AskedBy, Date)
VALUES
('', '$_POST[Module]', '$_POST[Name]', '')";
$row = !mysql_query($sq2,$con)
I want 'Date' column to update automatically in phpmyadmin table. 我希望'日期'列在phpmyadmin表中自动更新。 Not sure how to proceed. 不知道如何继续。
You can either set the default for the column to be NOW()
or just insert NOW()
with your query. 您可以将列的默认值设置为NOW()
也可以将NOW()
为查询。
$sq2 = "INSERT INTO querylog (QueryID, Module, AskedBy, `Date`)
VALUES ('', '$_POST[Module]', '$_POST[Name]', NOW())";
Please, don't use mysql_
functions in new code. 请不要在新代码中使用mysql_
functions。 They are no longer maintained and are officially deprecated. 它们不再维护,并且已被正式弃用。
One possible solution could be to change your date column to a timestamp. 一种可能的解决方案是将日期列更改为时间戳。 http://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html http://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html
An alternate solution would be to use a trigger. 另一种解决方案是使用触发器。
http://dev.mysql.com/doc/refman/5.0/en/triggers.html http://dev.mysql.com/doc/refman/5.0/en/triggers.html
In phpMyAdmin open up the SQL tab and paste something like: 在phpMyAdmin中打开SQL选项卡并粘贴如下内容:
DELIMITER $$
CREATE TRIGGER autoSetDate BEFORE INSERT ON yourDatabaseName.yourTableName
FOR EACH ROW
BEGIN
NEW.date=NOW();
END; $$
DELIMITER ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.