Advertisement
Guest User

Untitled

a guest
Nov 10th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Ostico
  5. * Date: 30/06/16
  6. * Time: 02:00
  7. */
  8.  
  9. /*
  10. # From OrientDB console create a schema named test and set it's properties as follow:
  11.  
  12. create class SubTest
  13. create property SubTest.id string
  14. create property SubTest.value1 double
  15. alter property SubTest.value1 default 0.0
  16. create property SubTest.value1Name string
  17. create property SubTest.value2 double
  18. alter property SubTest.value2 default 0.0
  19. create class Test extends V
  20. create property Test.attr1 embeddedlist SubTest
  21.  
  22. # download composer.phar and run:
  23.  
  24. php composer.phar --install
  25.  
  26. ## Replace in this script the right OrientDB IP and port and the clusterID of the class Test
  27. */
  28.  
  29. require "./vendor/autoload.php";
  30.  
  31. use PhpOrient\PhpOrient;
  32. use PhpOrient\Protocols\Binary\Data\ID;
  33. use PhpOrient\Protocols\Binary\Data\Record;
  34.  
  35. $client = new PhpOrient( '10.0.2.2', 2424 );
  36. $client->username = 'root';
  37. $client->password = 'root';
  38. $client->connect();
  39. $client->dbOpen( 'test', 'admin', 'admin' );
  40.  
  41. //create record
  42. $subOData = [
  43. "@type" => "d",
  44. "@class" => "SubTest",
  45. "id" => "123456-78980",
  46. "value1Name" => "Test",
  47. "value1" => 2000,
  48. "value2" => 33333,
  49. ];
  50.  
  51. $attr1Item = (new Record())->setOData($subOData)->setOClass("SubTest");
  52.  
  53. $odata = [
  54. "attr1" => [
  55. $attr1Item
  56. ],
  57. ];
  58.  
  59. $rec = ( new Record() )->setOClass("Test")->setOData( $odata )->setRid( new ID( 21 /* YOUR CLUSTER ID FOR TEST CLASS */ ) );
  60.  
  61. $rec = $client->recordCreate( $rec );
  62.  
  63. //re-load record
  64. $rec = $client->recordLoad( $rec->getRid() )[0];
  65.  
  66. //output
  67. print_r($rec);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement