【问题标题】:Fatal error: Call to a member function bindParam() on a non-object [duplicate]致命错误:在非对象上调用成员函数 bindParam() [重复]
【发布时间】:2014-02-23 13:36:58
【问题描述】:
$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'));

不知道为什么会出现错误。

【问题讨论】:

  • 可能是因为你在非对象上调用成员函数(方法)?显然,$db->prepare 没有返回对象。
  • @PavelS。 OP甚至没有prepare$setEndedDate
  • 哦,开枪。我没有使用 $db->prepare!谢谢!
  • $setEndedDate 是字符串,它不是对象。

标签: php


【解决方案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;

【讨论】:

  • @user3271847 :有效吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-13
  • 2011-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-29
相关资源
最近更新 更多