Detailed description and usage:
Using the class:
First of all you need to create a mysql database and import the RDQL_db tables structure
to that database, if your database is named foo you can do it using:
mysql foo < rdql_db.sql
This will create all the tables needed by the RDQL_db and RDQL_query_db classes. Now
in your script you have to connect to MySQL and selet the database where the tables
were created:
mysql_connect("localhost","root","");
mysql_select_db("foo");
If you created a MySQL user with permisions only to the foo database or the RDQL_db tables
just replace root,"" with the user name and password.
Storing, retrieving and deleting RDF documents
The RDQL_db class let's you store, retrieve and delete documents from the databse, examples:
$db = new RDQL_db();
$db->store_rdf_document("http://example.com/foo.rdf","foo"); //Store from URL using key=foo
$db->store_rdf_document("people.rdf","people"); //Store from the local file system
$db->remove_rdf_document("foo"); // Eliminate a document
$doc = $db->get_rdf_document("people"); // Retrieve a document
Querying the database
Once you have the RDF documents stored you can query the database using the RDQL_query_db class,
in the from section of the query you have to use the keys as you entered them to store the
documents, you can query multiple documents and you can even use * to query all the documents
in the database. Example:
SELECT ?x,?y,?z
FROM <people>,<salaries>
WHERE (?x,<dt:salary>,?y),(?x,<dt:age>,?z)
AND ?y>200
USING dt for <http://foo.org#>, rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
This will query documents stored with keys "salaries" and "people". You can check the file
"example.php" for some queries, documents and operations. You can also check the RDQL
tutorial for a description of what can you do with this RDQL implementation.
Documentation
Classes
RDQL_query_db
Extends: None
Description: This class implements the RDQL language for RDF documents stored in a MySQL database using the RDQL_db class.
Method Summary |
array |
rdql_query_db(string $query)
Queries documents in the database |
rdql_query_db
array rdql_query_db(string $query)
- This method is used to query RDF documents stored in a MySQL database, the documents are indicated in the FROM part of the RDQL query using the keys that you used when the documents were stored in the database using RDQL_db class.
-
- Parameters:
-
$query - The RDQL query, in the from part you should use * or a list of comma sepparated document keys enclosed by angle brackets. Example: <foo>,<people>
- Returns:
- An array of result rows. Each row is an asociative array mapping RDQL variables to their values.
- Throws:
None
RDQL_db
Extends: None
Description: A class to store, retrieve and delete RDF documents from Mysql. Once parsed and stored the documents can be queried using the RDQL_query_db class.
Method Summary |
string |
get_error(string $query)
Returns last error message |
void |
remove_rdf_document(string $key)
Removes an RDF document from the database |
boolean |
store_rdf_document(string $url, string $key)
Stores an RDF document in the database |
string |
get_rdf_document(string $key)
Retrieves a document from the database |
void |
set_warning_mode(boolean $mode)
Sets the warning mode for class errors |
get_error
string get_error()
- If a mehtod of this class fails then an error message is set in the object and you can ask for it using this method.
-
- Parameters:
-
- Returns:
- The last error message produced.
- Throws:
None
remove_rdf_document
void remove_rdf_document(string $key)
- Removes an RDF document from the database, you have to indicate the document Key to remove it.
-
- Parameters:
-
$key - The key of the document to be deleted (the key you used to store the document)
- Returns:
- Nothing
- Throws:
None
store_rdf_document
boolean store_rdf_document(string $url, string $key)
- This method is used to parse an RDF document from a path or URL and store it in the database with a given key. The key is what you use to retrieve, query or delete the document after it was stored.
-
- Parameters:
-
$url - URL or file-path of the RDF document to be stored
$key - Key for the document in the database
- Returns:
- True if the document was stored, false if not
- Throws:
None
get_rdf_document
string get_rdf_document(string $key)
- This method is used to retrieve an RDF document from the database using its key to access the document.
-
- Parameters:
-
$key - The key of the document to be retrieved
- Returns:
- The document as a PHP string
- Throws:
IF there's an error the method returns false and the error message can be accessed using get_error()
set_warning_mode
void set_warning_mode(boolean $mode)
- Sets the warning mode for class errors. When the warning mode is true then if theres an error in a class method a PHP warning is issued. If the warning mode is false then no warnings are reported and you can access the error message using get_error.
-
- Parameters:
-
$mode - True to set warning mode to true false to unset it
- Returns:
- Nothing
- Throws:
None
RDF_rdqldb_iterator
Extends: RDF_iterator
Description: This iterator can be used to implement the RDQL generic engine for RDF documents stored in a mysql database using the RDQL_db class.
Method Summary |
This class doesn´t have any method |
|