【发布时间】:2016-04-01 19:03:18
【问题描述】:
我正在尝试将日期时间插入 mysql 列,但出现此错误:
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
这是我用来获取日期时间并将其插入“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;
}
【问题讨论】:
-
在
$date周围加上引号。或者,考虑使用timestamps