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'));
 }
Exemplo n.º 2
0
$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());
    }
}
echo 'Creating DB...' . PHP_EOL;
try {
    $result = $db->DBCreate($dbName, OrientDB::DB_TYPE_LOCAL);
    echo 'Opening DB...' . PHP_EOL;