php中的当前时间戳生成和mysql中的更新

问题描述:

i want to create a timestamp by which i can know which post is modified when and all. in mysql databse, i made a coloumn called lastmodified, with type as timestamp. now, when i am updating the data in db, i want to update the current timestamp in last modified. how to do so? also could anyone please tell me, if any function exits for comparing these timestamps.

$now = time();

$query = "update storydb set lastmodified = '$now' where story_id = '$story_id'";
mysqli_query($con, $query);

我想创建一个时间戳,通过该时间戳我可以知道哪个帖子被修改了。 在mysql数据库中,我创建了一个名为lastmodified的coloumn,类型为timestamp。 现在,当我更新db中的数据时,我想更新上次修改的当前时间戳。 该怎么办? 任何人都可以告诉我,如果有任何函数退出比较这些时间戳。 p>

  $ now = time(); 
 
 $ query =“update storydb set lastmodified =  '$ now'where story_id ='$ story_id'“; 
mysqli_query($ con,$ query); 
  code>  pre> 
  div>

time() returns UNIX Timetamp in integer format e.g. 1223485636.

You want it in 2014-12-10 02:02:36

Use MySQL now() function instead of $now

$query = "update storydb set lastmodified = now() where story_id = '$story_id'";

now() is a MySQL function that returns current Time Stamp (including date).

No, its not unix timestamp that should be used in there, just a normal NOW() should suffice:

$query = "UPDATE storydb SET lastmodified = NOW() WHERE story_id = ?";
$update = $con->prepare($query);
$update->bind_param('s', $story_id);
$update->execute();

To insert current unix timestamp in data base

$time = time();
$qry = 'update db_name' set column_name = $time where condition;
mysql_query($qry);