stagas
stagas

Reputation: 4793

Graph-structured databases and Php

I want to use a graph database using php. Can you point out some resources on where to get started? Is there any example code / tutorial out there? Or are there any other methods of storing data that relate to each other in totally random/abstract situations?

-

Very abstract example of the relations needed: John relates to Mary, both relate to School, John is Tall, Mary is Short, John has Blue Eyes, Mary has Green Eyes, query I want is which people are related to 'Short people that have Green Eyes and go to School' -> answer John

-

Another example:

    TrackA -> ArtistA
           -> ArtistB

           -> AlbumA -----> [ label ]
           -> AlbumB -----> [   A   ]

           -> TrackA:Remix
           -> Genre:House

           -> [ Album ] -----> [ label ]
   TrackB  -> [   C   ]        [   B   ]

Example queries:

Which Genre is TrackB closer to? answer: House - because it's related to Album C, which is related to TrackA and is related to Genre:House

Get all Genre:House related albums of Label A : result: AlbumA, AlbumB - because they both have TrackA which is related to Genre:House

-

It is possible in MySQL but it would require a fixed set of attributes/columns for each item and a complex non-flexible query, instead I need every attribute to be an item by itself and instead of 'belonging' to something, to be 'related' to something.

Upvotes: 17

Views: 6045

Answers (8)

Pomme.Verte
Pomme.Verte

Reputation: 1792

You can also find a Rexster client for php : https://github.com/PommeVerte/rexpro-php

As extra information. Rexster can load graphs from various other graph dbs such as Neo4j and OrientDb among others.

Upvotes: 0

Gotisch
Gotisch

Reputation: 1

well taking into account this question is one year old, it might still be interesting to note that you can do such a query with every rdf datastore that supports sparql or comparable languages.

Upvotes: 1

Lvca
Lvca

Reputation: 9060

Take also a look to this article about the usage of OrientDB with PHP: http://www.odino.org/346/orientdb-the-graph-db-for-the-web

Upvotes: 0

rustyx
rustyx

Reputation: 85371

My suggestion is to pick a Java-based graph DB like OrientDB or neo4j and then use it via the PHP/Java bridge. In the near future neo4j (and at some point OrientDB as well) should get native php support and you can replace the bridge with native access.

Upvotes: 1

nawroth
nawroth

Reputation: 4361

There's some work going on to make the Neo4j graph database available from PHP, see this wiki page for more information! Regarding how to model your domain as a graph, the user mailing list tends to be pretty awesome.

Update: there's now a short getting started blog post for a PHP neo4j REST client.

Upvotes: 9

Zak
Zak

Reputation: 25205

It kind of sounds like you should approach it this way:

1) Code a graph object that will let you query your data the way you want.

2) Write a persistence layer for your object

3) optimize the calls that do your query's in the graph object to use database calls when appropriate (for example, if you need to conserve memory).

Upvotes: 1

TTT
TTT

Reputation: 2375

It looks like a semantic web problem. So you have to figure out how you can use PHP and the semantic web together. Maybe this link http://bnode.org/blog/2009/05/25/back-from-new-york-semantic-web-for-php-developers-trip can help?

Upvotes: 1

osti
osti

Reputation: 447

Sounds to me a little bit like a "typical" Prolog problem... which is a quite different programming language than PHP. But perhaps you could work with popen.

Or you define an SQL table with columns [ id, predicate, atom1, atom2 ], to store the truthness of "Mary has Green Eyes": predicate = "has", atom1 = "Mary", atom2 = "Green Eyes".

Now you could join and filter the predicates and attributes with the SQL of your choice.

Upvotes: 1

Related Questions