PHP code example of byjg / sparqllib

1. Go to this page and download the library: Download byjg/sparqllib library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

byjg / sparqllib example snippets


$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>";
}

$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"]
}