/** * 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')); }
* @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) { echo 'Deleting DB (in case of previous run failed)...' . PHP_EOL; try { $db->DBDelete($dbName); } catch (OrientDBException $e) { die('Failed to DBDelete(): ' . $e->getMessage()); }