$setEndedDate = ("UPDATE spaceships_list SET ended = :date WHERE id = :spaceship_id");
$setEndedDate->bindParam(":date", date_format($date, 'Y-m-d H:i:s'));
$setEndedDate->bindParam(":spaceship_id", $row["spaceship_id"]);
$setEnded->execute();
$endFlight = $db->prepare("DELETE FROM flights WHERE spaceship_id = :spaceship_id");
$endFlight->bindParam(":spaceship_id", $row["spaceship_id"]);
continue;
这会返回错误
Fatal error: Call to a member function bindParam() on a non-object
,该行指的是所示的第2行。
$setEndedDate->bindParam(":date", date_format($date, 'Y-m-d H:i:s'));
不确定我为什么会收到错误。
答案 0 :(得分:1)
你的$setEndedDate
是字符串,它应该是一个对象。
你的问题在这里:
$setEndedDate = ("UPDATE spaceships_list SET ended = :date WHERE id = :spaceship_id");
$setEndedDate
它应该是$endFlight
之类的对象。您有$endFlight
的正确对象,但您没有$setEndedDate
的对象。
试试这个:
$setEndedDate = $db->prepare("UPDATE spaceships_list SET ended = :date WHERE id = :spaceship_id");
$setEndedDate->bindParam(":date", date_format($date, 'Y-m-d H:i:s'));
$setEndedDate->bindParam(":spaceship_id", $row["spaceship_id"]);
$setEnded->execute();
$endFlight = $db->prepare("DELETE FROM flights WHERE spaceship_id = :spaceship_id");
$endFlight->bindParam(":spaceship_id", $row["spaceship_id"]);
continue;