Database Reference
In-Depth Information
Listing 8-5. Creating a Node
<?php
require_once '../vendor/autoload.php';
// Neo4jClient class
require_once '../neo4j/Neo4jClient.php';
// Create Neo4j client
$neo4jClient = new Everyman\Neo4j\Client('localhost', 7474);
Neo4Client::setClient($neo4jClient);
// setup the node
$user = $neo4jClient->makeNode();
// populate & save the node
$ user->setProperty('name', 'Greg')->setProperty('business', 'Graph Story')->save();
Retrieving and Updating a Node
Once nodes have been added to the database, you will need a way to retrieve and modify them. Listing 8-6 shows the
process for finding a node by its node id value and updating it.
Listing 8-6. Retrieving and Updating a Node
<?php
// Neo4jClient class
// ...omitted...
// Create Neo4j client
// ...omitted...
// retrieve the node by its node id value, in this case 10
$user = $neo4jClient->getNode(10);
// update & save the node
$user->setProperty('name', 'Greg')->setProperty('business', 'Crowdplace')->save();
Removing a Node
Once a node's graph id has been set and saved into the database, it becomes eligible to be removed when necessary.
In order to remove a node, set a variable as a node object instance and then call the delete method for the node
(Listing 8-7).
You cannot delete any node that is currently set as the start point or end point of any relationship. You must
remove the relationship before you can delete the node.
Note
 
 
Search WWH ::




Custom Search