开发者

How to generate and insert datetime into a mysql database (PHP)

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())");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜