Exemplo n.º 1
0
 public function testDoubleDeserialization()
 {
     $db_name = 'test_date';
     $client = new PhpOrient('localhost', 2424);
     $client->connect('root', 'root');
     try {
         $client->dbDrop($db_name, Constants::STORAGE_TYPE_MEMORY);
     } catch (\Exception $e) {
         //            echo $e->getMessage();
         $client->getTransport()->debug($e->getMessage());
     }
     $client->dbCreate($db_name, Constants::STORAGE_TYPE_MEMORY, Constants::DATABASE_TYPE_GRAPH);
     $client->dbOpen($db_name, 'admin', 'admin');
     $client->command("create class Test extends V");
     $client->command("create property Test.myDate date");
     $client->command("insert into Test set myDate='2015-01-01'");
     $start = microtime(true);
     $result = $client->query("SELECT FROM Test WHERE myDate <= '2015-10-17'");
     $end = microtime(true);
     $this->assertTrue($end - $start < 1);
     $this->assertNotEmpty($result);
 }
 /**
  * @param string $sql
  * @param array  $params
  * @param array  $options
  *
  * @return mixed
  */
 public function send($sql = null, array $params = array(), array $options = array())
 {
     return $this->connection->command($sql);
 }
Exemplo n.º 3
0
 public function testRecordData()
 {
     $db_name = 'test_record_data';
     $client = new PhpOrient('localhost', 2424);
     $client->connect('root', 'root');
     $this->skipTestByOrientDBVersion(['2.0.13', '1.7.10']);
     try {
         $client->dbDrop($db_name, Constants::STORAGE_TYPE_MEMORY);
     } catch (\Exception $e) {
         //            echo $e->getMessage();
         $client->getTransport()->debug($e->getMessage());
     }
     $client->dbCreate($db_name, Constants::STORAGE_TYPE_MEMORY, Constants::DATABASE_TYPE_GRAPH);
     $client->dbOpen($db_name, 'admin', 'admin');
     $client->command("create class Test extends V");
     $client->command("create property Test.id string");
     $client->command("alter property Test.id DEFAULT uuid()");
     $rec = (new Record())->setOData([])->setRid(new ID(11));
     $record = $client->recordCreate($rec);
     $this->assertArrayHasKey('id', $record);
     $this->assertNotEmpty($record['id']);
 }
<?php

use PhpOrient\PhpOrient;
use PhpOrient\Protocols\Binary\Data\ID;
use PhpOrient\Protocols\Binary\Data\Record;
require 'vendor/autoload.php';
$client = new PhpOrient('orientdb3', 2424);
$client->connect('root', 'rootpwd');
if ($client->dbExists('demo')) {
    $client->dbDrop('demo');
}
$client->dbCreate('demo');
$client->dbOpen('demo');
// Create a new collection
$clusterId = $client->command('create class Elements extends V');
// Add new documents
$document1 = new Record();
$document1->setOData(['now' => date('Y-m-d H:i:s')]);
$document1->setRid(new ID($clusterId));
$document2 = new Record();
$document2->setOData(["created" => ['during' => ['VilniusPHP', 'event']]]);
$document2->setRid(new ID($clusterId));
$record1 = $client->recordCreate($document1);
$record2 = $client->recordCreate($document2);
// Read them all
$documents = $client->query('select from Elements');
foreach ($documents as $document) {
    /** @var $document Record */
    echo '<h2>' . $document->getRid() . '</h2>';
    echo "<div><b>Class:</b> {$document->getOClass()}</b>";
    echo "<div><b>Revision:</b> {$document->getVersion()}</b>";