我正在尝试从orient db数据库中选择插入的数据并将其回显出去? 我怎么能用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');
}
它只是在屏幕上打印'Array'
我在Windows机器上运行Apache php服务器。 如何从数据库获取数据并在网站上打印。
当我用于每个循环打印元素时
我的脚本只是超时
$records = $db->query("select from Nation");
foreach ($records as $v)
echo $v;
如果我使用print_r($ records);
它提供以下输出
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* ) ) )
这是我的表
答案 0 :(得分:1)
更好地使用 PhpOrient 库它是由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
答案 1 :(得分:0)
打印结果。而不是echo
print_r($records);
要迭代结果,请使用foreach
或for
首先使用foreach
作为:
if(count($records) > 0){//check if we have a result
foreach($records as $value){//loop
print_r($value);
}
}