2014-02-23 33 views
-1
$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; 

上這將返回錯誤致命錯誤:調用一個成員函數bindParam()的非對象

Fatal error: Call to a member function bindParam() on a non-object 

與線reffering於所示的行號2。

$setEndedDate->bindParam(":date", date_format($date, 'Y-m-d H:i:s')); 

不知道爲什麼我得到錯誤。

+0

也許是因爲你是一個非對象上調用成員函數(方法)?顯然,$ db-> prepare沒有返回一個對象。 –

+0

[致命錯誤:調用成員函數bindParam()](http://stackoverflow.com/questions/7941089/fatal-error-call-toa-a-member-function-bindparam)或[this ](http://stackoverflow.com/questions/4488035/call-to-a-member-function-bind-param-on-a-non-object)或[this](http://stackoverflow.com/問題/ 18921670/fatal-error-call-to-a-member-function-bind-param-on-a-non-object)或[this](http://stackoverflow.com/questions/18401682/call-成員函數綁定參數非對象) – Kermit

+0

@PavelS。 OP甚至沒有在'$ setEndedDate'上準備' – kero

回答

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; 
+0

@ user3271847:它有效嗎? –

相關問題