如何将 MySql 时间戳列更新为 PHP 上的当前时间戳?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5869392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:44:49  来源:igfitidea点击:

How to update MySql timestamp column to current timestamp on PHP?

phpmysqldatabasetimestampsql-update

提问by Abhi

I want to update the columns of data type timestampmanually through my PHP code.

我想timestamp通过我的 PHP 代码手动更新数据类型的列。

Can you please tell me how to do that?

你能告诉我怎么做吗?

回答by Harry Joy

Use this query:

使用此查询:

UPDATE `table` SET date_date=now();


Sample code can be:

示例代码可以是:

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

mysql_query("UPDATE `table` SET date_date=now()");

mysql_close($con);
?>

回答by Madbreaks

Another option:

另外一个选项:

UPDATE `table` SET the_col = current_timestamp

Looks odd, but works as expected. If I had to guess, I'd wager this is slightly faster than calling now().

看起来很奇怪,但按预期工作。如果我不得不猜测,我敢打赌这比调用now().