Skip to content

xp-forge/neo4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neo4J connectivity

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version

This library implements Neo4J connectivity via its REST API.

Examples

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.

Format characters

  • %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.

About

Neo4J connectivity for XP Framework

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages