byjg/sparqllib

Simple library to query SPARQL from PHP

2.0.0 2021-10-31 05:20 UTC

This package is auto-updated.

Last update: 2024-10-15 18:11:48 UTC


README

Build Status SensioLabsInsight

Copyright 2010,2011,2012 Christopher Gutteridge & University of Southampton Licensed as LGPL

Info

Example:

$db = new \SparQL\Connection( "http://rdf.ecs.soton.ac.uk/sparql/" );
$db->ns( "foaf","http://xmlns.com/foaf/0.1/" );

$sparql = "SELECT * WHERE { ?person a foaf:Person . ?person foaf:name ?name } LIMIT 5";
$result = $db->query( $sparql );

$fields = $result->fieldArray();

print "<p>Number of rows: " . $result->numRows() . " results.</p>";
print "<table class='example_table'>";
print "<tr>";
foreach( $fields as $field )
{
   print "<th>$field</th>";
}

Simplified call

$results = new \SparQL\Connection::get( "http://rdf.ecs.soton.ac.uk/sparql/" )
            ->withNamespace( "foaf","http://xmlns.com/foaf/0.1/" )
            ->fetch("SELECT * WHERE { ?person a foaf:Person . ?person foaf:name ?name } LIMIT 5");

foreach ($results as $item) {
    print "<th>" . $item["person"]
}

Run tests

Just type:

phpunit