RDF
[ class tree: RDF ] [ index: RDF ] [ all elements ]

Source for file test_StoringModelsInDatabase.php

Documentation is available at test_StoringModelsInDatabase.php

  1. <?php 
  2. // ----------------------------------------------------------------------------------
  3. // PHP Script: test_StoringModelsInDatabase.php
  4. // ----------------------------------------------------------------------------------
  5. /*
  6.  * This is an online demo of RAP's database backend.
  7.  * It shows how to peristently store rdf models in a database.
  8.  *
  9.  * @author Radoslaw Oldakowski <radol@gmx.de>
  10.  */
  11. ?>
  12.  
  13.  
  14. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  15. <html>
  16. <head>
  17.     <title>Test Store Models in Database</title>
  18. </head>
  19. <body>
  20.  
  21. <?php 
  22. // Include RAP
  23. require_once 'RDF.php';
  24. require_once 'RDF/Store/MDB.php';
  25. require_once 'RDF/Model/MDB.php';
  26. require_once 'RDF/Model/Memory.php';
  27. // # 1. Connect to MsAccess database (via ODBC)
  28. // # ------------------------------------------
  29. // Connect to MsAccess (rdf_db DSN) database using connection settings
  30. // defined in constants.php :
  31. $rdf_database =new RDF_Store_MDB(
  32.     array(
  33.         'phptype' => 'mysql',
  34.         'username' => 'metapear',
  35.         'password' => 'funky',
  36.         'hostspec' => 'localhost',
  37.         'database' => 'rdf'
  38.     )array());
  39. // # 2. Store a memory model in database.
  40. // # ------------------------------------
  41. // Load an RDF-Documtent into a memory model
  42. // Filename of an RDF document
  43. $base "Example1.rdf";
  44. // Create a new memory model
  45. $Model_Memory =new RDF_Model_Memory();
  46. // Load and parse document
  47. $Model_Memory->load($base);
  48. // Now store the model in database
  49. // An unique modelURI will be generated
  50. $rdf_database->putModel($Model_Memory);
  51. // You can also provide an URI for the model to be stored
  52. $modelURI "Example1.rdf";
  53. // But then you must check if there already is a model with the same modelURI
  54. // otherwise the method putModel() will return FALSE
  55. if ($rdf_database->modelExists($modelURI))
  56.     echo "Model with the same URI: '$modelURI' already exists";
  57. else
  58.     $rdf_database->putModel($Model_Memory$modelURI);
  59. // # 3. Create a new database model
  60. // # ------------------------------
  61. $modelURI "newModel_MDB";
  62. // Base URI of the new model (optional)
  63. $baseURI "baseURIofMyNewModel_MDB#";
  64. // get a new Model_MDB
  65. if ($rdf_database->modelExists($modelURI)) {
  66.     echo "Model with the same URI: '$modelURI' already exists";
  67. else {
  68.     $Model_MDB $rdf_database->getNewModel($modelURI$baseURI);
  69. }
  70. // # 4. List all models stored in database
  71. // # -------------------------------------
  72. // Get an array with modelURI and baseURI of all models stored in rdf database
  73. $list $rdf_database->listModels();
  74. // Show the database contents
  75. foreach ($list as $model{
  76.     echo "modelURI: " $model['modelURI'"<br>";
  77.     echo "baseURI : " $model['baseURI'"<br><br>";
  78.  
  79. ?>
  80. </body>
  81. </html>

Documentation generated on Mon, 11 Mar 2019 15:39:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.