Home » Php » How to update MySql timestamp column manually to current timestamp through PHP

How to update MySql timestamp column manually to current timestamp through PHP

Posted by: admin April 23, 2020 Leave a comment

Questions:

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

Can you please tell me how to do that?

How to&Answers:

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

Answer:

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().