Method GET By ID
This method used for display data which selected by ID in your table in the form of JSON
format
$app->get('/getmovie/{id}', function ($request, $response){
try{
$id = $request->getAttribute('id');
$con = getDB();
$sql = "SELECT * FROM t_movie WHERE id_movie = :id";
$pre = $con->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$values = array(
':id' => $id
);
$pre->execute($values);
$result = $pre->fetch();
if($result){
return $response->withJson(array('status' => 'true','result'=>$result),200);
}else{
return $response->withJson(array('status' => 'Movies Not Found'),422);
}
}
catch(\Exception $ex){
return $response->withJson(array('error' => $ex->getMessage()),422);
}
});