Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Ostico
- * Date: 30/06/16
- * Time: 02:00
- */
- /*
- # From OrientDB console create a schema named test and set it's properties as follow:
- create class SubTest
- create property SubTest.id string
- create property SubTest.value1 double
- alter property SubTest.value1 default 0.0
- create property SubTest.value1Name string
- create property SubTest.value2 double
- alter property SubTest.value2 default 0.0
- create class Test extends V
- create property Test.attr1 embeddedlist SubTest
- # download composer.phar and run:
- php composer.phar --install
- ## Replace in this script the right OrientDB IP and port and the clusterID of the class Test
- */
- require "./vendor/autoload.php";
- use PhpOrient\PhpOrient;
- use PhpOrient\Protocols\Binary\Data\ID;
- use PhpOrient\Protocols\Binary\Data\Record;
- $client = new PhpOrient( '10.0.2.2', 2424 );
- $client->username = 'root';
- $client->password = 'root';
- $client->connect();
- $client->dbOpen( 'test', 'admin', 'admin' );
- //create record
- $subOData = [
- "@type" => "d",
- "@class" => "SubTest",
- "id" => "123456-78980",
- "value1Name" => "Test",
- "value1" => 2000,
- "value2" => 33333,
- ];
- $attr1Item = (new Record())->setOData($subOData)->setOClass("SubTest");
- $odata = [
- "attr1" => [
- $attr1Item
- ],
- ];
- $rec = ( new Record() )->setOClass("Test")->setOData( $odata )->setRid( new ID( 21 /* YOUR CLUSTER ID FOR TEST CLASS */ ) );
- $rec = $client->recordCreate( $rec );
- //re-load record
- $rec = $client->recordLoad( $rec->getRid() )[0];
- //output
- print_r($rec);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement