Problem with insert data query
Closed this issue · 8 comments
I'm trying to insert data into my RDF database using PHP. This is my code:
$query = "PREFIX vc: <http://www.fbk.eu/ontologies/2016/virtualcoach/v1#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
INSERT DATA {
vc:AnimalLipid_6666661 vc:amountNutrient 6666.66 .
vc:AnimalLipid_6666661 vc:unit \"g\" .
vc:AnimalLipid_6666661 rdf:type vc:AnimalLipid .
vc:AnimalLipid_6666661 rdf:type owl:NamedIndividual .
}";
$sp_write = new Endpoint($end);
$res = $sp_write->query($query);
$err = $sp_write->getErrors();
if ($err) {
print_r($err);
throw new Exception(print_r($err,true));
}
The result is an error saying "Sorry, you have no permission to access the database". Why? There is no autentication in my RDF database. My server is graphDB. How can I make it work? Where I'm wrong?
Thanks in advance for your help.
First of all thanks for your kind reply! I've tried to add the readandwrite parameter in the constructor
$sp_write = new Endpoint($end,false);
The whole code is the following:
$query = "PREFIX vc: <http://www.fbk.eu/ontologies/2016/virtualcoach/v1#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
INSERT DATA {
vc:AnimalLipid_6666661 vc:amountNutrient 6666.66 .
vc:AnimalLipid_6666661 vc:unit \"g\" .
vc:AnimalLipid_6666661 rdf:type vc:AnimalLipid .
vc:AnimalLipid_6666661 rdf:type owl:NamedIndividual .
}";
$sp_write = new Endpoint($end,false);
$res = $sp_write->query($query);
$err = $sp_write->getErrors();
if ($err) {
print_r($err);
throw new Exception(print_r($err,true));
}
Now I got a different error. The output is the following:
Array ( [0] => Error query : PREFIX vc: PREFIX rdfs: PREFIX rdf: PREFIX owl: INSERT DATA { vc:AnimalLipid_888930 vc:amountNutrient 8889.3 . vc:AnimalLipid_888930 vc:unit "g" . vc:AnimalLipid_888930 rdf:type vc:AnimalLipid . vc:AnimalLipid_888930 rdf:type owl:NamedIndividual . } Error endpoint: http://localhost:7200/repositories/virtualcoachupdate/ Error http_response_code: 404 Error message: [1] => Error query : PREFIX vc: PREFIX rdfs: PREFIX rdf: PREFIX owl: INSERT DATA { vc:AnimalLipid_888930 vc:amountNutrient 8889.3 . vc:AnimalLipid_888930 vc:unit "g" . vc:AnimalLipid_888930 rdf:type vc:AnimalLipid . vc:AnimalLipid_888930 rdf:type owl:NamedIndividual . } Error endpoint: http://localhost:7200/repositories/virtualcoachsparql/ Error http_response_code: 200 Error message: Error parsing XML result:Invalid document end Response : ) Exception encountered, of type "Exception"
It somehow try to reach "virtualcoachupdate" in my endpoint which doesn't exist. Any idea? Thanks in advance again.
I tried to put both false and true in the constructor after setting the endpoint but still no results :(
$sp_write = new Endpoint($end,false);
and
$sp_write = new Endpoint($end,true);
Is this the right?
Yes I've tried to execute the query manually from GraphDB and it works like a charm. I tried to enable debug mode now and this is the output.`
query : PREFIX vc: PREFIX rdfs: PREFIX rdf: PREFIX owl: INSERT DATA { vc:AnimalLipid_93230 vc:amountNutrient 932.3 . vc:AnimalLipid_93230 vc:unit "g" . vc:AnimalLipid_93230 rdf:type vc:AnimalLipid . vc:AnimalLipid_93230 rdf:type owl:NamedIndividual . } endpoint : http://localhost:7200/repositories/virtualcoachupdate/ http_response_code : 404 message : ####################### =========================>>>>>>Error query : PREFIX vc: PREFIX rdfs: PREFIX rdf: PREFIX owl: INSERT DATA { vc:AnimalLipid_93230 vc:amountNutrient 932.3 . vc:AnimalLipid_93230 vc:unit "g" . vc:AnimalLipid_93230 rdf:type vc:AnimalLipid . vc:AnimalLipid_93230 rdf:type owl:NamedIndividual . } Error endpoint: http://localhost:7200/repositories/virtualcoachupdate/ Error http_response_code: 404 Error message: =========================>>>>>>Error query : PREFIX vc: PREFIX rdfs: PREFIX rdf: PREFIX owl: INSERT DATA { vc:AnimalLipid_93230 vc:amountNutrient 932.3 . vc:AnimalLipid_93230 vc:unit "g" . vc:AnimalLipid_93230 rdf:type vc:AnimalLipid . vc:AnimalLipid_93230 rdf:type owl:NamedIndividual . } Error endpoint: http://localhost:7200/repositories/virtualcoachsparql/ Error http_response_code: 200 Error message: Error parsing XML result:Invalid document end Response : `
And this is the error array printed out:
Array ( [0] => Error query : PREFIX vc: PREFIX rdfs: PREFIX rdf: PREFIX owl: INSERT DATA { vc:AnimalLipid_93230 vc:amountNutrient 932.3 . vc:AnimalLipid_93230 vc:unit "g" . vc:AnimalLipid_93230 rdf:type vc:AnimalLipid . vc:AnimalLipid_93230 rdf:type owl:NamedIndividual . } Error endpoint: http://localhost:7200/repositories/virtualcoachupdate/ Error http_response_code: 404 Error message: [1] => Error query : PREFIX vc: PREFIX rdfs: PREFIX rdf: PREFIX owl: INSERT DATA { vc:AnimalLipid_93230 vc:amountNutrient 932.3 . vc:AnimalLipid_93230 vc:unit "g" . vc:AnimalLipid_93230 rdf:type vc:AnimalLipid . vc:AnimalLipid_93230 rdf:type owl:NamedIndividual . } Error endpoint: http://localhost:7200/repositories/virtualcoachsparql/ Error http_response_code: 200 Error message: Error parsing XML result:Invalid document end Response : ) Exception encountered, of type "Exception"
Any idea? Thank you very much for your patience!
Hi
I will look into it and then get back to you. Thank you very much! Have a nice day :)