1
votes

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 ?

2

2 Answers

1
votes

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\".
    }";
1
votes

I have solved the problem as I have tried to use the delete command without any variable (?s), and instead use the actual subject such:

$query= "DELETE DATA{ds:S1 foaf:firstName \"Lina\".}";

I think that is because you can't delete something you don't know. and I used the following to execute it:

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