I am trying to execute an INSERT on a SPARQL endpoint in PHP using the ARC2 library. This fails with the error "Could not properly handle " PREFIX dc:"
The SPARQL UPDATE query is taken from the W3C specification and works just fine on my Jena-Fuseki control panel:
$query = '
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA
{
<http://example/book007> dc:title "A new book" ;
dc:creator "A.N.Other" .
}
';
But even variations of the query without a PREFIX statement just result in a similar error "Could not properly handle " INSERT DATA {" in my PHP code.
My PHP code is as follows:
include_once('./lib/arc2/ARC2.php');
$config = array(
//db
'db_name' => 'arc2',
'db_user' => 'root',
'db_pwd' => '-',
//store
'store_name' => 'arc_tests'
);
$store = ARC2::getStore($config);
if (!$store->isSetUp())
$store->setUp();
$res = $store->query($query);
echo var_dump($store->getErrors());
echo "<br><br>executed INSERT, returned: ";
echo var_dump($res);
This version is using a native ARC2 store to reduce potential error sources. I am actually trying to interact with a remote store:
$config = array( 'remote_store_endpoint' => 'http://localhost:3030/data/update', );
$store = ARC2::getRemoteStore($config);
Both give me the same error, however.
In the end I want to connect to the remote SPARQL endpoint of my Jena Fuseki server and interactively insert and retrieve data with that in PHP. If you have any other libraries or clean solutions how to interact through the SPARQL protocol in PHP, I am happy to change my approach.
It seems, ARC2 does not support SPARQL 1.1 parsing.
Instead it only supports a simplified SPARQL+ for UPDATE queries. The following query successfully inserts a new triple into the ARC2 store:
$query = 'INSERT DATA
{
<http://example/book1> dc:title "A new book" ;
dc:creator "A.N.Other" .
}';
Unfortunately, with this limited SPARQL+ it seems impossible to do UPDATEs through a remote store on my Jena Fuseki instance. Either ARC2 is complaining about the SPARQL 1.1 conform query syntax as given in the question, or Jena Fuseki is complaining about the SPARQL+ query syntax that seems specific to ARC2.
Any advice? I posted a new question about this: https://stackoverflow.com/questions/26858594/php-sparql-1-1-library-for-semantic-web-stack-php-sparql-jena-fuseki