Mitch8910 Mitch8910 - 3 months ago 15
SQL Question

MySQL update DATETIME to NOW() using PHP

This all worked before I added the section to update "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

When this is called I want to make last_update the date and time now. In the database it is currently a DATETIME, and when I last_update I origianly set them to NOW();

Doing this I get the error Fatal error: Cannot pass parameter 2 by reference in.... Directory

I know it expects a variable, I'm not sure how to fix it though. I tried setting

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

No prevail. Any help?


Why you need to bind, just put NOW() directly

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