RDF development in PHP with a PostGreSQL triple store thanks to the LibRDF OO wrapper for redland/librdf

Redland/librdf offers powerful features like being able to persist an RDF model to a relational database (only PostGreSQL seems to work on my setup with 1.0.16, but I may have misconfigured it). You can then do SPARQL queries over the model, and lots of other nice things.

Unfortunately, the default PHP bindings are not really object-oriented, so the code isn’t looking so good.

But thanks to a gentleman named David Shea, there is an object-oriented library named LibRDF (case is sensitive), that helps write nice looking PHP.

I discovered it via the blog post of Felix Ostrowski, who took over the maintenance of the LibRDF library (still the docs live on the original author’s site).

In his post, Felix illustrates how you may use it to parse Richard Cyganiak’s FOAF profile.

But the examples he gives don’t illustrate the full potential of persistence of the RDF graph into the DB.

Here’s my contribution in 2 examples that will hopefully help : first, one that load Richard’s FOAF to the DB, and one, that later retrieve the saved model and perform the same query (both pushed to my github clone of the library).

There may be some problems with the use of librdf, including its availability, as it is not full PHP of course… and I’ve heard of memory management problems, but, depening on your needs, this may be quite handy for writing Linked Data applications.

2 thoughts on “RDF development in PHP with a PostGreSQL triple store thanks to the LibRDF OO wrapper for redland/librdf”

  1. Btw, MySQL works too, provided that you fix the SQL templates for table creation in /usr/share/redland/mysql-v1.ttl by replacing TYPE= with ENGINE=

Leave a Reply

Your email address will not be published.