gpt4 book ai didi

php - MySQL 使用 PHP 将 DATETIME 更新为 NOW()

转载 作者:行者123 更新时间:2023-11-29 01:39:20 26 4
gpt4 key购买 nike

在我添加更新“last_update”的部分之前,这一切都有效。

if((time() - $last_update) > 7200){
$sql = $dbh->prepare("UPDATE item_list SET quantity=:quantity, price=:price, last_update=:now WHERE item_name=:itemname");
$sql->bindParam(':quantity', $json->volume);
$sql->bindParam(':price', $json->lowest_price);
$sql->bindParam(':itemname', $row['Item_Name']);
$sql->bindParam(':now', "NOW()"); //This doesn't work
$sql->execute();
}

当它被调用时,我想将 last_update 设置为现在的日期和时间。在数据库中,它当前是一个 DATETIME,当我上次更新时,我最初将它们设置为 NOW();

这样做我得到错误 fatal error :无法通过引用在...目录中传递参数 2

我知道它需要一个变量,但我不确定如何修复它。我试过设置

$now = "NOW()";
$sql->bindParam(':now', $now);

不占优势。有帮助吗?

最佳答案

为什么要绑定(bind),直接放NOW()就可以了

$sql = $dbh->prepare("UPDATE item_list SET quantity=:quantity, price=:price, last_update=now() WHERE item_name=:itemname");

关于php - MySQL 使用 PHP 将 DATETIME 更新为 NOW(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30127652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com