我想手动将时间戳值插入mySQL数据库:
$timestamp = "2018-05-15 00:00:00";
$name = "Fred";
$pdo = $db->prepare('INSERT INTO data (timestamp,name) values(:timestamp,:name)');
$pdo->execute(array(
':timestamp' => $timestamp,
':name' => $name
));
但它总是插入现在的日期,而不是我变量的日期。
MYSQL表:
id | timestamp | name
----------------------
| |
id = int(11) AUTO_INCREMENT
timestamp = timestamp (Standard: CURRENT TIMESTAMP, Attribute: ON UPDATE CURRENT TIMESTAMP)
name = varchar (255)
答案 0 :(得分:1)
如果要在时间戳字段中手动插入日期,则应将其类型从timestamp (Standard CURRENT TIMESTAMP)
更改为datetime
。只有这样它才会起作用,否则总会节省当前的系统时间。
详细了解datetime