/** * Return registered connection under given connectionName * * @param string $connectionName * * @return \OrientDB */ public function getConnection($connectionName = 'default') { if ($this->connections->containsKey($connectionName)) { return $this->connections->get($connectionName); } $configuration = $this->getConfiguration($connectionName); $this->connections->set($connectionName, $database = new \OrientDB($configuration->getHost(), $configuration->getPort(), $configuration->getTimeout())); $database->connect($configuration->getUser(), $configuration->getPassword()); return $database; }
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')); }
/** * Execute command by sending data to server, receive initial reply * @throws null|OrientDBException * @throws OrientDBException * @return mixed */ public function execute() { $this->socket->debug = $this->debug; $this->socket->send($this->requestBytes); if (is_null($this->parent->protocolVersion)) { $this->debugCommand('protocol_version'); $serverProtocolVersion = $this->readShort(); $this->parent->setProtocolVersion($serverProtocolVersion); } if ($this->opType == self::DB_CLOSE) { // No incoming bytes return null; } $this->debugCommand('request_status'); $this->requestStatus = $this->readByte(); $this->debugCommand('TransactionID'); $requestTransactionID = $this->readInt(); if ($requestTransactionID !== $this->currentTransactionID) { throw new OrientDBException('Transaction ID mismatch'); } if ($this->requestStatus === chr(OrientDBCommandAbstract::STATUS_SUCCESS)) { $data = $this->parseResponse(); if ($this->opType === self::DB_OPEN) { $this->parent->setSessionIDDB($this->sessionID); } elseif ($this->opType === self::CONNECT) { $this->parent->setSessionIDServer($this->sessionID); } return $data; } elseif ($this->requestStatus === chr(OrientDBCommandAbstract::STATUS_ERROR)) { $exception = null; while ($this->readByte() === chr(OrientDBCommandAbstract::STATUS_ERROR)) { $this->debugCommand('exception_javaclass'); $javaException = $this->readString(); $this->debugCommand('exception_message'); $javaExceptionDescr = $this->readString(); $exception = new OrientDBException($javaException . ': ' . $javaExceptionDescr, 0, is_null($exception) ? null : $exception); } throw $exception; } else { throw new OrientDBException('Unknown error'); } }
* This file can be used as a starting point to understand way OrientDB-PHP * works. * @author Anton Terekhov <*****@*****.**> * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2012 * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE * @link https://github.com/AntonTerekhov/OrientDB-PHP * @package OrientDB-PHP * @subpackage Example */ $rootPassword = '******'; $dbName = 'example'; $clusterName = 'default'; require_once 'OrientDB/OrientDB.php'; echo 'Connecting to server...' . PHP_EOL; try { $db = new OrientDB('localhost', 2424); } catch (Exception $e) { die('Failed to connect: ' . $e->getMessage()); } echo 'Connecting as root...' . PHP_EOL; try { $connect = $db->connect('root', $rootPassword); } catch (OrientDBException $e) { die('Failed to connect(): ' . $e->getMessage()); } try { $exists = $db->DBExists($dbName); } catch (OrientDBException $e) { die('Failed to execute DBExists(): ' . $e->getMessage()); } if ($exists) {
<?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));
* This file can be used to speedtest OrientDB-PHP library on creating, * modifying and deleting records. * Before use, you must create DB named 'speedtest' manually. * * @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; } }
/** * @covers Fuel\Core\OrientDB::rollback_transaction * @expectedException Fuel\Core\OrientDB\NotSupportException */ public function testRollback_transaction() { OrientDB::rollback_transaction(); }