Intro
67 |This is a very simple RDF library to query SPARQL from PHP. It currently ignores language and datatype information to make it feel as similar as possible to the normal PHP SQL libraries.
68 |-
69 |
- Download: sparqllib.php (LGPL) 70 |
If you want to get started really quickly, the following command line will install sparqllib.php. You should run it in the same directory as where your PHP code resides.
72 |Or get the latest version from Github.
76 |Also hosted on this site is Graphite, a simple PHP library for querying RDF data.
77 | 78 | Really Quick Interface 80 | #If you just want to get the damn data, use this style.
81 | #render_example( "examples/quick.php" ); 82 | ?> 83 |Classic mysql_query style
84 |The library provides functions very similar to mysql_* for comfort.
85 | 88 | 89 |Object style
90 |The object-based interface is a bit tidier than the sparql_ style methods.
91 | 94 | 95 |Quick and dirty
96 |The quickest way to get at some data.
97 | 100 | 101 |Rows, Values and Datatypes
102 |All the interfaces end up giving you an array of values, one per field. They also define the type of each value and, if available, the datatype or language of a literal value.
103 |$row["myfield"] | The value of the field in this row of results. |
---|---|
$row["myfield.type"] | The type of the value. Either 'uri','bnode' or 'literal'. |
$row["myfield.datatype"] | This may be set for literal values. |
$row["myfield.language"] | This may be set for literal values. |
Endpoint Capabilities Tests
113 | 114 |This allows you to test if an endpoint supports and allows certain SPARQL features. It doesn't currently cache, so every test results in a query. I have been trying to write software which runs against multiple endpoints and it's really frustrating not knowing what an endpoint can/can't do.
115 |The first and most simple test is just to see if this looks like a SPARQL endpoint. Just call $db->alive( 3 ); where 3 is the timeout in seconds.
116 | 119 |I'm very open to suggestions for useful additional tests (with example SPARQL which runs in some endpoints, but not others)
120 | 121 | 124 | 125 |Contact
126 |Get in touch with me at cjg@ecs.soton.ac.uk and you could have a look at our web team blog.
127 |