/** * */ function loadModel($url) { // load model from file if ($url) { $this->m = new MemModel(); $this->m->load($url); } else { $db = new DbStore(PUBBY_DB_DRIVER, PUBBY_DB_HOST, PUBBY_DB_DB, PUBBY_DB_USER, PUBBY_DB_PASS); $this->m = $db->getModel(PUBBY_DBMODEL); } }
} elseif (substr($modelId, 0, 3) == "db:") { // Database backed model $modelURI = substr($modelId, 3); $database = new DbStore($NETAPI_DB_DRIVER, $NETAPI_DB_HOST, $NETAPI_DB_DB, $NETAPI_DB_USER, $NETAPI_DB_PASS); $type = 'model'; if ($database->modelExists($modelURI) == False) { $type = 'dataset'; if ($database->datasetExists($modelURI) == False) { // Model not found in the database header('HTTP/1.0 404 Not Found'); echo "404 - Model " . $model . " not found\n"; return; } } if ($type == 'model') { $model1 = $database->getModel($modelURI); } else { $model1 = $database->getDatasetDb($modelURI); } } elseif (substr($modelId, 0, 5) == "file:") { // File backed model $modelURI = substr($modelId, 5); $model1 = new MemModel(); $model1->load($modelURI); } else { // Undefined repository type header('HTTP/1.0 500 Internal Server Error'); echo "500 - I don't understand " . $modelId; } // Process query or update operation if ($_SERVER['QUERY_STRING'] != '') {
<title>Test Store Models in Database</title> </head> <body> <?php // Include RAP define("RDFAPI_INCLUDE_DIR", "./../api/"); include RDFAPI_INCLUDE_DIR . "RdfAPI.php"; ## 1. Connect to MsAccess database (via ODBC) ## ------------------------------------------ // Connect to MsAccess (rdf_db DSN) database using connection settings // defined in constants.php : $rdf_database = new DbStore(); ## 2. Load a DbModel ## ----------------- $dbModel = $rdf_database->getModel("example1.rdf"); // Output the model as HTML table $dbModel->writeAsHtmlTable(); echo "<br><br>"; ## 3. Add a statement tho the DbModel ## ---------------------------------- // Ceate a new statement $statement = new Statement(new Resource("http://www.w3.org/Home/Lassila"), new Resource("http://description.org/schema/Description"), new Literal("Lassilas persönliche Homepage", "de")); // Add the statement to the DbModel $dbModel->add($statement); // Output the string serialization of the DbModel echo $dbModel->toStringIncludingTriples(); echo "<br><br>"; ## 4. Search statements ## --------------------- // Search for statements having object $literal