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

Source for file test_ManipulateModelMDB.php

Documentation is available at test_ManipulateModelMDB.php

  1. <?php 
  2. // ----------------------------------------------------------------------------------
  3. // PHP Script: test_ManipulatingModel_MDB.php
  4. // ----------------------------------------------------------------------------------
  5. /*
  6.  * This is an online demo of RAP's database backend.
  7.  * This script demonstrates some methods to manipulate a Model_MDB.
  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. Load a Model_MDB
  40. // # -----------------
  41. $Model_MDB $rdf_database->getModel("Example1.rdf");
  42. // Output the model as HTML table
  43. $Model_MDB->writeAsHtmlTable();
  44.  
  45. echo "<br><br>";
  46. // # 3. Add a statement tho the Model_MDB
  47. // # ----------------------------------
  48. // Ceate a new statement
  49. $statement =RDF_Statement::factory(
  50.     RDF_Resource::factory('http://www.w3.org/Home/Lassila'),
  51.     RDF_Resource::factory('http://description.org/schema/Description'),
  52.     RDF_Literal::factory('de')
  53. );
  54.  
  55. // Add the statement to the Model_MDB
  56. $Model_MDB->add($statement);
  57. // Output the string serialization of the Model_MDB
  58. echo $Model_MDB->toStringIncludingTriples();
  59.  
  60. echo "<br><br>";
  61. // # 4. Search statements
  62. // # ---------------------
  63. // Search for statements having object $literal
  64. $literal =RDF_Literal::factory('de');
  65. $res $Model_MDB->find(nullnull$literal);
  66. // Output the result
  67. $res->writeAsHtmlTable();
  68.  
  69. echo "<br>";
  70. // # 5. 5. Replace nodes and serialize the Model_MDB to XML/RDF
  71. // # --------------------------------------------------------
  72. // replace a literal
  73. $Model_MDB->replace(nullnull,
  74.     RDF_Literal::factory("de"),
  75.     RDF_Literal::factory ("Lassila's personal Homepage""en")
  76. );
  77. // Serialize to RDF
  78. $Model_MDB->writeAsHtml();
  79.  
  80. echo "<br><br>";
  81. // # 6. Remove a statement
  82. // # ---------------------
  83. $Model_MDB->remove(
  84.         RDF_Resource::factory("http://www.w3.org/Home/Lassila"),
  85.         RDF_Resource::factory("http://description.org/schema/Description"),
  86.         RDF_Literal::factory("Lassila's personal Homepage""en")
  87.     )
  88. );
  89. // Output the Model_MDB
  90. $Model_MDB->writeAsHtmlTable();
  91.  
  92. echo "<br>";
  93. // # 7. Generate a Model_Memory and compare both models
  94. // # ----------------------------------------------
  95. // Generate a Model_Memory
  96. $Model_Memory $Model_MDB->getMemModel();
  97. // Compare this Model_MDB withe the generated Model_Memory
  98. $res $Model_MDB->equals($Model_Memory);
  99.  
  100. if ($res)
  101.     echo "models are equal";
  102. else
  103.     echo "models are different";
  104.  
  105. echo "<br>";
  106. // # 8. Save Model_MDB to file
  107. // # ----------------------------------------------
  108. // Save Model_MDB to file (XML/RDF)
  109. $Model_MDB->saveAs("Output.rdf");
  110. // Save Model_MDB to file (N3)
  111. $Model_MDB->saveAs("Output.n3");
  112. // close the Model_MDB
  113. $Model_MDB->close();
  114.  
  115. ?>
  116.  
  117. </body>
  118. </html>

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