Hey I need to insert current datatime into mysql database.. 开发者_StackOverflowthis is the format:
0000-00-00 00:00:00
Most easily done with MySQL directly using the NOW()
function.
INSERT INTO tbl (datecol) VALUES (NOW());
If you need PHP to produce a value other than the exact current timestamp, use the format:
date('Y-m-d H:i:s', $some_unix_timestamp);
As a MySQL query:
INSERT INTO table (fieldname) VALUES (NOW())
And wrapped in PHP:
$db = new PDO($dsn, $user, $password);
$db->query("INSERT INTO table (fieldname) VALUES (NOW())");
精彩评论