public function scratch() { global $databaseConfig; $server = $databaseConfig['server']; $port = $databaseConfig['port']; $serverUsername = $databaseConfig['serverusername']; $serverPassword = $databaseConfig['serverpassword']; $username = $databaseConfig['username']; $password = $databaseConfig['password']; $dbName = $databaseConfig['database']; $clusterName = 'default'; $log = ''; try { $db = new OrientDB('localhost', 2424); $log .= 'Connected to localhost on port 2424 <br/>'; } catch (Exception $e) { SS_Log::log(new Exception(print_r('Failed to connect: ' . $e->getMessage(), true)), SS_Log::NOTICE); } try { $connect = $db->connect($serverUsername, $serverPassword); $log .= 'Connected to DB as root <br />'; } catch (OrientDBException $e) { SS_Log::log(new Exception(print_r('Failed to connect(): ' . $e->getMessage(), true)), SS_Log::NOTICE); } $exists = $db->DBExists($dbName); if ($exists) { $log .= "{$dbName} exists <br />"; } else { SS_Log::log(new Exception(print_r('DB doesnt exist', true)), SS_Log::NOTICE); } $clusters = $db->DBOpen($dbName, $username, $password); $log .= "opened {$dbName} as admin user"; //Get properties of a table try { SS_Log::log(new Exception(print_r($clusters, true)), SS_Log::NOTICE); $results = $db->command(OrientDB::COMMAND_QUERY, 'desc TestObject'); SS_Log::log(new Exception(print_r($results, true)), SS_Log::NOTICE); } catch (OrientDBException $e) { SS_Log::log(new Exception(print_r($e->getMessage(), true)), SS_Log::NOTICE); } return $this->customise(new ArrayData(array('Title' => 'Orient DB Sandbox', 'SubTitle' => '', 'Content' => $log, 'Form' => '')))->renderWith(array('SandboxController', 'AppController')); }
} catch (OrientDBException $e) { die('Failed to execute DBExists(): ' . $e->getMessage()); } if ($exists) { echo 'Deleting DB (in case of previous run failed)...' . PHP_EOL; try { $db->DBDelete($dbName); } catch (OrientDBException $e) { die('Failed to DBDelete(): ' . $e->getMessage()); } } echo 'Creating DB...' . PHP_EOL; try { $result = $db->DBCreate($dbName, OrientDB::DB_TYPE_LOCAL); echo 'Opening DB...' . PHP_EOL; $clusters = $db->DBOpen($dbName, 'writer', 'writer'); foreach ($clusters['clusters'] as $cluster) { if ($cluster->name === $clusterName) { $clusterID = $cluster->id; } } echo 'Create record...' . PHP_EOL; $record = new OrientDBRecord(); $record->data->FirstName = 'Bruce'; $record->data->LastName = 'Wayne'; $record->data->appearance = 1938; $recordPos = $db->recordCreate($clusterID, $record); echo 'Created record position: ' . $recordPos . PHP_EOL . PHP_EOL; echo 'Load record...' . PHP_EOL; $recordLoaded = $db->recordLoad($clusterID . ':' . $recordPos); echo 'Load record result: ' . $recordLoaded . PHP_EOL . PHP_EOL;
<?php require_once 'OrientDB/OrientDB.php'; $db = new OrientDB('localhost'); $db->DBOpen('tinkerpop', 'admin', 'admin'); $result = $db->selectGremlin('g.v1.outE', '*:-1'); var_dump(count($result)); var_dump(count($db->cachedRecords));
* @author Anton Terekhov <*****@*****.**> * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE * @link https://github.com/AntonTerekhov/OrientDB-PHP * @package OrientDB-PHP * @subpackage Example */ require 'OrientDB/OrientDB.php'; $records = 100000; $time_c = microtime(true); echo 'Socket' . PHP_EOL; $db = new OrientDB('localhost', 2424); echo microtime(true) - $time_c . PHP_EOL; $time_c = microtime(true); echo 'OpenDB DB' . PHP_EOL; $clusters = $db->DBOpen('speedtest', 'admin', 'admin'); echo microtime(true) - $time_c . PHP_EOL; $time_c = microtime(true); $result = array(); for ($i = 0; $i < $records; $i++) { try { $position = $db->recordCreate(2, 'Name:"Bill",Id:' . $i); $result[] = $position; } catch (OrientDBException $e) { echo $e->getMessage() . PHP_EOL; } } echo 'Done create ' . $records . PHP_EOL; echo microtime(true) - $time_c . PHP_EOL; $callback = function (&$item, $key) { $item = '#2:' . $item;