Search code examples
phpsparqlsesame

Updating RDF data using php on sesame server


I have a question about updating RDF data using PHP code on sesame server. I have tried to use the SPARQL update from sesame endpoint and successed. However, using PHP it didn't gave any error but when I check the RDF data nothing change!!

in the connecting, I have used this link to proceed the update: http://localhost:8080/Sesame/repositories/MyData/statements

and the following code to achieve the update:

$query= "
DELETE DATA{
  ?s foaf:firstName \"Lina\".
}
WHERE {
  ?s foaf:firstName \"Lina\".
}";


$result = $sparql->query($query); 

I thought I have to change query function now since now, it is not query and it is update. Additionally, I have tried

$result = $sparql->update($query);

and I got an error!!

what is wrong or what should I do ?


Solution

  • The problem is that you are confusing/mixing DELETE DATA and DELETE WHERE - which are different types of update operations in SPARQL. Simply remove the DATA keyword from your query, like so:

    $query= "
    DELETE {
      ?s foaf:firstName \"Lina\".
    }
    WHERE {
      ?s foaf:firstName \"Lina\".
    }";
    

    This will remove all statements with predicate foaf:firstName and object "Lina".

    And since you want to delete the exact triples you're matching, you do not have to repeat the graph pattern in the DELETE clause, so your query can become shorter:

    $query= "
        DELETE 
        WHERE {
          ?s foaf:firstName \"Lina\".
        }";