I am making some kind of website to watch movies/tv shows, just for fun.And I am stuck, basically I made function getMovieFromAPI that takes given ID and searches inside database for imdbID, then I use that imdbID to find info about that movie from API.And everything is working great, I can use echo inside funcion to show data.My question is, how can I use this data outside of this function, example: when I want to see year and plot of movie how can I get that data from this function.I tried returning it as array and all other stuff.I hope I explained well what I want
My code:
function getMovieFromAPI($IDD) {
global $connect, $omdbAPIKey;
$query[0] = "SELECT * FROM movies WHERE ID = '$IDD' LIMIT 1";
$results[0] = $connect -> query( $query[0] );
$row[0] = $results[0] -> fetch_assoc();
$ID = $row[0]['imdbID'];
$apiurl = 'http://www.omdbapi.com/?i='.$ID.'&apikey='.$omdbAPIKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);}
Edit: as requested, I made test page just to call this function and see if it works
getMovieFromAPI('1');