开发者

Inserting a datetime value from php into MySQL

开发者 https://www.devze.com 2023-01-15 16:44 出处:网络
I have a column with datetime datatype called \'updated_at\' in a mysql table,where i want the current date and time.Im trying to insert a record into the mysql table from php,as follows:

I have a column with datetime datatype called 'updated_at' in a mysql table,where i want the current date and time.Im trying to insert a record into the mysql table from php,as follows:

mysql_query("INSERT INTO my_table (service_name,service_status,service_comment,user_name,updated_at) VALUES($service_name,$service_status,$service_comment,$user_name,$updated_开发者_C百科at) ")

$updated_at is defined as follows:

$updated_at = date("D, d M Y H:i:s O");

But the insert is not taking place. Any way to fix this problem ?

Please help Thank You


Use a date format that MySQL understands:

$updated_at = date('Y-m-d H:i:s');


INSERT INTO my_table (service_name,service_status,service_comment,user_name,updated_at) VALUES($service_name,$service_status,$service_comment,$user_name,NOW())

For mode details, see reference for NOW() function.


date('Y-m-d H:i:s') OR use NOW() OR set default value to collumn CURRENT_TIMESTAMP

0

精彩评论

暂无评论...
验证码 换一张
取 消