致命错误:在非对象上调用成员函数bindParam()

时间:2014-02-23 13:36:58

标签: php

$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'));

不确定我为什么会收到错误。

1 个答案:

答案 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;