Discover Graph Databases with Neo4j and PHP

Originally published at: http://www.sitepoint.com/discover-graph-databases-neo4j-php/

This entry is part 2 of 1 in the series Graph Databases in PHP with Neo4j

Graph Databases in PHP with Neo4j

  • Discover Graph Databases with Neo4j and PHP

In this post, we’ll be learning about Neo4j, the leading graph database, and ways to use it with PHP. In a followup post, we’ll be building a proper graph application powered by Silex.


Graph databases are now one of the core technologies of companies dealing with highly connected data.

Business graphs, social graphs, knowledge graphs, interest graphs and media graphs are frequently in the (technology) news – and for a reason. The graph model represents a very flexible way of handling relationships in your data, and graph databases provide fast and efficient storage, retrieval and querying for it.

Neo4j, the most popular graph database, has proven its ability to deal with massive amounts of highly connected data in many use-cases.

During the last GraphConnect conference, TomTom and Ebay’s Shuttle demonstrated the value a graph database adds to your company to, for instance, provide fantastic customer experiences or to enable complex route-map editing. Neo4j is developed and supported by Neo Technology – a startup which has grown into a well respected database company.

A short Introduction

For the newcomers, here is a short introduction to graph databases and Neo4j, apart from the theoretical glance we threw at it last year.

What is a Graph ?

A graph is a generic data structure, composed of of nodes (entities) connected by relationships. Sometimes, those are also called vertices and edges. In the property graph model, each node and relationship can be labeled and holds hold any number of properties describing it.

Continue reading this article on SitePoint

Hi Christophe

Good articles

There is a missing arguments on a listing with create item with $parameters - should be:

$query = 'CREATE (user:User {name: {name} }) RETURN user';
$parameters = array('name' => 'Maxime');
$client->sendCypherQuery($query, $parameters);

Thanks, fixed!

Thank you @duythien

Good catch. Thanks.

Also worth pointing out that other types of graph database exist, for example those that follow the Resource Description Framework (RDF) model, commonly known as Triple/Quad stores.

They have the benefit of a W3C standard query language behind them (SPARQL[1]), a defined RESTful protocol[2] and quite a few databases available, both open source and commercial, that have some benefits over Neo4J - for example the ability to scale out with a shared nothing architecture (MarkLogic, Virtuoso Cluster Edition and 4Store).

It all depends on your workload, of course, and for some people the RDF model won’t provide all they need, however, it’s a powerful model and worth exploring if you’re thinking of using a graph database in an upcoming project.

[1] http://www.w3.org/TR/sparql11-query/
[2] http://www.w3.org/TR/rdf-sparql-protocol/

I’d love it if you could write a simplified explanation on these not unlike this one, to introduce people to these concepts in a manner less convoluted than typical W3 specs tend to be. This post will have a part 2 in which we’ll be building a friend-recommendations powered Silex app, so showing such approaches from different angles with different technologies would be priceless. Let me know if you’re interested or know someone who is.

Sure, I’d be happy to do that. I agree, the W3C specs can be a bit impenetrable, but the basic concepts behind RDF are quite simple when explained well.

Excellent! Do get in touch via bruno.skvorc@sitepoint.com and we’ll discuss further!

Of course there exist multiple graph databases, like there exist multiple sql databases or key-value stores.

RDF is in my opinion a subset of the possibilities a graph database can offer.
There are SPARQL plugins for Neo4j and many tutorials on the internet about it.

Now as mentioned by Bruno, the goal of the article is to go deeper with a simple demo application providing social network features and timelines.

Hi, thanks for the great introduction !

I don’t know anything about Cypher, but shouldn’t $params here :

$query = 'MATCH (user1:User {name:{name1}}), (user2:User {name:{name2}}) CREATE (user1)-[:FOLLOWS]->(user2)';
$params = ['user1' => 'Kenneth', 'user2' => 'Maxime'];
$client->sendCypherQuery($query, $params);

be like :

$params = ['name1' => 'Kenneth', 'name2' => 'Maxime'];

?

I wouldn’t say subset per se, more tangential.

Looking at experiences with the SPARQL plugin for Neo4J it’s much slower than a dedicated RDF Triple Store.

The other niceities you get with the RDF model is identifying everything with a URI, making the merging of datasets trivial (in the best case), and formal ontologies which provide various predefined models for building your data, e.g. FOAF, Dublin Core Terms, SIOC etc.

Great article @ikwattro

Hi jhuet,

Thanks for reading the article. No the parameters are name1 and name2.

Parameters in Cypher are enclosed in {} , while user1 and user2 here are node identifiers.

Thank you

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.