Scripting

Setting Current_Timestamp/Datetime to field/column value in MySQL doesn’t work from Php using PDO connection.

Say in one of your table you have a field which you want to set with current time value from your database server.

However, setting timestamp/datetime values from php to MySQL using PDO didn’t work for me in case of both NOW(), SYSDATE(), FROM_UNIXTIME(NOW())

The alternate/workaround, I found is to set MySQL default value for the selected column to auto-populate with the current_timestamp of the MySQL server. This worked fine.

 

ALTER TABLE testusers CHANGE creation_time creation_time TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ;

 

<

p>image

Advertisements