2017-06-03 26 views
-1

我想從東方分貝數據庫中選擇插入的數據並將其回顯出來? 我該如何使用php來做到這一點?如何從東方分貝「選擇」數據,並使用php顯示它

這是我迄今所做

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'); 
     } 

它只是打印在屏幕上

我運行Windows機器上的Apache PHP服務器「數組」。我如何從數據庫中獲取數據並在網站上打印。

當我使用每個循環,打印出的元素

我的劇本只是超時

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

如果我使用的print_r($記錄);

它提供了以下的輸出

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] => [email protected]_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] => [email protected]_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] => [email protected]_Name:"Canada",Iso_code:"CA" [data] => OrientDBData Object ([data:OrientDBData:private] => Array () [record:OrientDBData:private] => OrientDBRecord Object *RECURSION*))) 

如何將它轉換到合適的形式。像它 enter image description here

僅取的名字,這是我的表

+0

您會收到結果的數組。用於foreach或while循環遍歷數組並打印每個結果 –

+0

發佈數據庫模式 – Akintunde007

回答

0

打印結果。取而代之的echo

print_r($records); 

爲了遍歷結果,要麼使用foreachfor

首先檢查是否我們有一些成果,採用foreach爲:

if(count($records) > 0){//check if we have a result 
    foreach($records as $value){//loop 
    print_r($value); 
    } 
} 
+0

它打印出什麼 – Akintunde007

+0

https://pastebin.com/AY7JuDDQ這是它的輸出如何使它有意義。它的名字 –

1

更好地利用PhpOrient圖書館它是由東方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

相關問題