使用PHP将datetime插入mysql datetime列时出错

使用PHP将datetime插入mysql datetime列时出错,php,mysql,datetime,Php,Mysql,Datetime,我试图将datetime插入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:

我试图将datetime插入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
下面是我用来获取datetime并将其插入“dt”datetime类型列的代码

$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;
}
$dateTime=newdatetime();
$date=$dateTime->format('Y-m-dh:i:s');
$sql=“插入到价格中(priceLBTC,dt)
价值($bitcoinPrice,$date)”;
if($conn->query($sql)==TRUE){
echo“新记录创建成功”;
}否则{
echo“Error:”.$sql.“
”$conn->Error; }
$sql=“插入价格(priceLBTC,dt)

值(“.$conn->quote($BITCONPRICE)。”,“$conn->quote($date)。”

您收到错误,原因是您的日期时间值未按如下所示引用,因此DB引擎将抛出一个错误,假设您打算提供更多值

INSERT INTO prices (priceLBTC, dt) VALUES (421.59, 2015-12-27 15:41:09)
                                                   ^.. Here
您需要使用单引号引用datetime值,如

INSERT INTO prices (priceLBTC, dt) VALUES (421.59, '2015-12-27 15:41:09')

$date
周围加引号。另外,考虑使用<代码>时间戳<代码>,谢谢!我认为它不需要,因为价格本来就没有。