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

Abhi picture Abhi · May 3, 2011 · Viewed 114k times · Source

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

Can you please tell me how to do that?

Answer

Harry Joy picture Harry Joy · May 3, 2011

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);
?>