我想要的日期時間插入到一個MySQL列,但我得到這個錯誤:錯誤插入日期時間到MySQL datetime列使用PHP
Error: INSERT INTO prices (priceLBTC, dt) VALUES (421.59, 2015-12-27 15:41:09) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '15:41:09)' at line 2
下面是我用得到的代碼datetime並將其插入到「dt」日期時間類型列中。
$dateTime = new DateTime();
$date = $dateTime->format('Y-m-d H:i:s');
$sql = "INSERT INTO prices (priceLBTC, dt)
VALUES ($bitcoinPrice, $date)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
看跌行情。另外,可以考慮使用'timestamps' – Ohgodwhy