json = new HTML_AJAX_JSON(SERVICES_JSON_LOOSE_TYPE); #WILL: corrected class name } // This method submits a query and synchronously returns its result. // If authentication credentials are passed, it uses them as an HTTP Cookie. function read($queryobj, $credentials) { global $debug; //WILL: to show query and response // Put the query into an envelope object $envelope = array("qname" => array("query" => $queryobj)); // Serialize the envelope object to JSON text $querytext = $this->json->encode($envelope); if ($debug) { print "
$querytext"; } //WILL: show query // Then URL encode the serialized text $encoded = urlencode($querytext); // Now build the URL that represents the query // Note that we use an HTTP GET request for read queries $url = $this->URL . "?queries=" . $encoded; // Use the curl library to send the query and get response text $request = curl_init($url); // Return the result instead of printing it out. curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE); // If we have credentials, send them with the request as a cookie if ($credentials) curl_setopt($request, CURLOPT_COOKIE, $credentials); // Now fetch the URL $responsetext = curl_exec($request); curl_close($request); // Parse the server's response from JSON text into a PHP array $response = $this->json->decode($responsetext); // Return null if the query was not successful if ($response["qname"]["code"] != "/api/status/ok") { //WILL: Database API has changed since example was written echo "
$responsetext"; return null; } if ($debug) echo "
$responsetext"; //WILL: Show the response // Otherwise, open the envelope and just return the actual result object return $response["qname"]["result"]; } } ?>