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