Blog di Bernardino (Dino) Ciuffetti

08 Mar 12 How to execute a HTTP/Rest Query to NuvolaBase distributed database with PHP

As previously said, is a great service that permits you to have a distributed nosql document database in the cloud. This is very cool: think each time you would had the need of a database always available in the cloud that you would access via simple HTTP/Rest queries. The possibilities are endless.

Here is a very simple but powerful PHP curl agent to submit commands (queries) to nuvolabase via HTTP.

* Author: Dino Ciuffetti <>
* Object: Execute a remote query to a distributed database on (free account) using HTTP (OrientDB REST API)

/* user configurable parameters */
$nuvolabasedb = ‘db$free$youruser$yourdb’;
$command = ‘select from yourclass’;
$user = ‘admin’;
$password = ‘qwerty’;
$useragent = “NuvolaBase PHP REST agent/v0.8 (compatible; Mozilla 4.0; MSIE 5.5;”;
/* END of user configurable parameters */

$nuvolabasehost = ‘’;
$url = ‘http://’.$user.’:’.$password.’@’.’’.$nuvolabasedb.’/sql/’;

$ch = curl_init();

// set user agent
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// return the result or false in case of errors
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// set the target url
curl_setopt($ch, CURLOPT_URL, $url);

// do basic login authentication

// howmany parameter to post
curl_setopt($ch, CURLOPT_POST, 1);

// the post data to send
curl_setopt($ch, CURLOPT_POSTFIELDS, $command);

// execute curl,fetch the result and close curl connection
$res = curl_exec ($ch);
curl_close ($ch);

// display result
if ($res !== FALSE);
print_r (json_decode($res));


Please use the attached file.


Reader's Comments



    I am trying to connect to my own OrientDB rest interface and have tried using your code above but I get 401 unauthorised. I have tried base64 encoding the password, sending in the URL and sending as separate username/password but nothing seems to work. DO you have any advice?

    THanks in advance

    Reply to this comment

      Hi there. The script should be used as is, without base64()ing the password, or something like that.

      You should be able to use the nuvolabase REST API just using the script I put in attach to the following article, just change your user, password, database name and query.

      Reply to this comment

Lascia un commento