0
我正在使用Slim Framework處理我的REST風格的Web服務,並且當我嘗試從3個表中獲取數據時出現此錯誤。{closure}()缺少參數2;
這是在我的課的功能:
public function getCard($card_id, $card_type_id, $user_id) {
$stmt = $this->conn->prepare("SELECT uc.id, c.card_name, ct.category, c.card_desc, c.card_picture ,c.status, c.created_at from cards c, user_cards uc, cards_type ct WHERE c.card_type_id = ct.card_type_id AND c.card_id = uc.card_id AND uc.user_id = ?");
if ($stmt == FALSE) {
die($this->conn->error);
} else {
$stmt->bind_param("iii", $card_id, $card_type_id, $user_id);
if ($stmt->execute()) {
$res = array();
$stmt->bind_result($id, $card_name, $category, $card_desc, $card_picture, $status, $created_at);
$stmt->fetch();
$res["id"] = $id;
$res["card_name"] = $card_name;
$res["category"] = $category;
$res["card_desc"] = $card_desc;
$res["card_picture"] = $card_picture;
$res["status"] = $status;
$res["created_at"] = $created_at;
$stmt->close();
return $res;
} else {
return NULL;
}
}
}
而且這是在index.php文件的代碼:
$app->get('/cards/users/:card_id', 'authenticate', function($card_id, $card_type_id) {
global $user_id;
$response = array();
$db = new Card();
// fetch card
$result = $db->getCard($card_id, $card_type_id, $user_id);
if ($result != NULL) {
$response["error"] = false;
$response["id"] = $result["id"];
$response["card_name"] = $result["card_name"];
$response["category"] = $result["category"];
$response["card_desc"] = $result["card_desc"];
$response["card_picture"] = $result["card_picture"];
$response["status"] = $result["status"];
$response["createdAt"] = $result["created_at"];
echoRespnse(200, $response);
} else {
$response["error"] = true;
$response["message"] = "The requested resource doesn't exists";
echoRespnse(404, $response);
}
});
難道我寫的東西錯了嗎?
我已經嘗試過的方式,但我得到了錯誤太多,因爲我寫上我的課這樣的代碼:公共職能getCard($ card_id的,$ card_type_id,$ USER_ID){ – 2014-11-01 05:51:53
或者我的查詢出錯了? – 2014-11-01 05:53:05
查看查詢,只有一個問號,所以你只能綁定一個參數。看看這是否有效。 – 2014-11-01 05:58:39