Skip to content
Advertisement

How to ‘SELECT’ data from orient db and display it using php

i am trying to select inserted data from orient db database and to echo it out ? how can i do this using php ?

This is what i have done so far

require('OrientDB/OrientDB.php');
$db = new OrientDB('localhost', 2424);





        $connected = $db->connect('root', 'hello');
        $config = $db->DBOpen('tabe', 'root', 'hello');
        if($connected)
        {

              $records = $db->query("select from Nation");

              echo $records;


        }
        else
        {
           die('Server Error');
        }

it just prints ‘Array’ on screen

i am running a Apache php server on windows machine. how can i get the data from the databse and print in on the website.

when i use for each loop to print out the element

my script just time out

 $records = $db->query("select from Nation");
              foreach ($records as $v)
                  echo $v;

if i use print_r($records);

it gives the following output

Array ( [0] => OrientDBRecord Object ( [isParsed:OrientDBRecord:private] => [className:OrientDBRecord:private] => [type] => d [clusterID:OrientDBRecord:private] => 169 [recordPos:OrientDBRecord:private] => 0 [recordID:OrientDBRecord:private] => 169:0 [version] => 4 [content:OrientDBRecord:private] => Nation@in_partOf:%AQAAAAIAwQAAAAAAAAAAAMIAAAAAAAAAAA==;,Country_Name:"India",Iso_code:"IN" [data] => OrientDBData Object ( [data:OrientDBData:private] => Array ( ) [record:OrientDBData:private] => OrientDBRecord Object *RECURSION* ) ) [1] => OrientDBRecord Object ( [isParsed:OrientDBRecord:private] => [className:OrientDBRecord:private] => [type] => d [clusterID:OrientDBRecord:private] => 170 [recordPos:OrientDBRecord:private] => 0 [recordID:OrientDBRecord:private] => 170:0 [version] => 4 [content:OrientDBRecord:private] => Nation@Country_Name:"United States of America",Iso_code:"US" [data] => OrientDBData Object ( [data:OrientDBData:private] => Array ( ) [record:OrientDBData:private] => OrientDBRecord Object *RECURSION* ) ) [2] => OrientDBRecord Object ( [isParsed:OrientDBRecord:private] => [className:OrientDBRecord:private] => [type] => d [clusterID:OrientDBRecord:private] => 171 [recordPos:OrientDBRecord:private] => 0 [recordID:OrientDBRecord:private] => 171:0 [version] => 2 [content:OrientDBRecord:private] => Nation@Country_Name:"Canada",Iso_code:"CA" [data] => OrientDBData Object ( [data:OrientDBData:private] => Array ( ) [record:OrientDBData:private] => OrientDBRecord Object *RECURSION* ) ) )

how to convert it in to suitable form . like taking only names from it enter image description here

this is my table

Advertisement

Answer

Better use PhpOrient Library it is the officially supported library by orient db

    $client = new PhpOrient();
        $client->hostname = 'localhost';
        $client->port     = 2424;
        $client->username = 'your_username';
        $client->password = 'your_password';

        $client->connect();
        $client->dbOpen('Your_db_name');

         $query = "SELECT FROM NATION";
         $result = $client->query($query);


       $result =  json_encode($result);
       $result = json_decode($result);

foreach ($result as $row){
       echo $row->oData->Country_Name;
       echo $row->oData->Iso_code;
}

phporient : https://github.com/orientechnologies/PhpOrient.git

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement