Skip to content

Commit

Permalink
Improved demo.php
Browse files Browse the repository at this point in the history
  • Loading branch information
electric-al committed Jun 1, 2010
1 parent 8c53fb1 commit 5f8c076
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions demo.php
@@ -1,35 +1,59 @@
<?php

/**
* Include the API PHP file
*/
require('php-neo-rest.php');

/**
* Create a graphDb connection
* Note: this does not actually perform any network access,
* the server is only accessed when you use the database
*/
$graphDb = new GraphDatabaseService('http://localhost:9999/');

/**
* Lets create some nodes
* Note: Unlike the java API, these nodes are NOT saved until you call the save() method (see below)
*/
$firstNode = $graphDb->createNode();
$secondNode = $graphDb->createNode();
$thirdNode = $graphDb->createNode();

/**
* Assign some attributes to the nodes and save the,
*/
$firstNode->message = "Hello, ";
$firstNode->save();

$secondNode->message = "world!";
$secondNode->someOtherAttribute = 'blah blah blah';
$secondNode->save();

$thirdNode->message = "third node";
$thirdNode->save();

/**
* Create a relationship between some nodes. These can also have attributes.
* Note: Relationships also need to be saved before they exist in the DB.
*/
$relationship = $firstNode->createRelationshipTo($secondNode, 'KNOWS');
$relationship->message = "brave Neo4j";
$relationship->save();

$relationship2 = $thirdNode->createRelationshipTo($secondNode, 'LOVES');
$relationship2->save();


/**
* Dump each node we created
*/
dump_node($firstNode);
dump_node($secondNode);
dump_node($thirdNode);


/**
* A little utility function to display a node
*/
function dump_node($node)
{
$rels = $node->getRelationships();
Expand Down

0 comments on commit 5f8c076

Please sign in to comment.