This library implements Neo4J connectivity via its REST API.
Running a query can be done via open() (which yields one record at a time) or query() (which collects the results in an array):
use com\neo4j\Graph;
use util\cmd\Console;
$g= new Graph('http://user:pass@neo4j-db.example.com:7474/db/data');
$q= $g->open('MATCH (t:Topic) RETURN t.name, t.canonical');
foreach ($q as $record) {
Console::writeLine('#', $record['t.canonical'], ': ', $record['t.name']);
}To retrieve single results (or NULL if nothing is found), use fetch():
if ($topic= $g->fetch('MATCH (t:Topic{id:%s}) RETURN t', $id)) {
Console::writeLine('Found topic ', $topic);
}Formatting parameters uses printf-like format tokens. These will take care of proper escaping and type casting:
use com\neo4j\Graph;
use util\cmd\Console;
$g= new Graph('http://user:pass@neo4j-db.example.com:7474/db/data');
$g->query('CREATE (p:Person) SET t.name = %s, t.id = %d', $name, $id);Batch statements can be executed via the execute() method.
%s: Format a string%d: Format a decimal number%f: Format a floating point numer%b: Format a boolean%v: Copy value into parameter%l: Copy label into query%c: Copy literal into query%%: A literal percent sign
Positional parameters (starting at 1) may be used, e.g. %2$s.

