开发者

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

开发者 https://www.devze.com 2023-04-08 15:46 出处:网络
Hey I need to insert current datatime into mysql database.. 开发者_StackOverflowthis is the format:

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

精彩评论

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

关注公众号