function freebase_query ($query
{
$queryarray = array'q'=>array'query'=>array$query)));
$jsonquerystr = json_encode$queryarray);
$jsonquerystr = urlencode$jsonquerystr);
$apiendpoint = "http://api.freebase.com/api/service/mqlread?queries"
$ch = curl_init();
curl_setopt$ch, CURLOPT_URL, "$apiendpoint=$jsonquerystr");
curl_setopt$ch, CURLOPT_HEADER, 0);
curl_setopt$ch, CURLOPT_RETURNTRANSFER, 1);
$jsonresultstr = curl_exec$ch);
curl_close$ch);
$resultarray = json_decode$jsonresultstr, true);
if (isset$resultarray'q']['result'])) {
return $resultarray'q']['result'];
} else {
if (isset$resultarray'q']['messages'][0]['message'])) {
throw new Exception"Error: "$resultarray'q']['messages'][0]['message']);
} else {
throw new Exception"Error");
}
}
}