topical media & game development
server-php-xml-class-rdql-db-class-rdql-db.htm / htm
<html>
<head>
<title>RDQL DB(class_rdql_db.php)</title>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div align="center">
<table border="0" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#aaaaee" class="text" align="center"><a href="http://phpxmlclasses.sourceforge.net/">PHP XML Classes</a></td>
</tr>
</table>
<table border="0" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#aaaaee" class="textblbl" align="center">RDQL DB (class_rdql_db.php)</td>
</tr>
</table>
<br/>
<table border="0" width="80%">
<tr>
<td bgcolor="#eeeeff" class="text">Description: This class implements the <a href="rdql.html">RDQL</a> language to query RDF documents stored in a
MySQL database. The RDF documents can be stored, retrieved and deleted from the database using the RDQL_db class, documents
can be stored from file paths or URLs<br/><br/>
Since RDF documents are parsed and stored in the database as RDF statements the RDQL implementation is fast since the
database is scanned for RDF statements without the need to parse the document (parse once, query many).<br/><br/>
There're two classes in this package to be used: RDQL_db implements methods to store,delete and retrieve documents
while RDQL_query_db implements the RDQL language engine.
</td>
</tr>
</table>
<br/>
<table border="0" bgcolor="ddddff" width="80%">
<tr>
<td valign="top" class="text" width="50%"><b>NEWS:</b>
<ul>
<li> 2002-07-03 First version of this class released.
</ul>
</td>
<td valign="top" width="50%" class="text">
This class code as well as the documentation are hosted at <a href="http://www.sourceforge.net">SourceForge</a>
please visit our <a href="http://phpxmlclasses.sourceforge.net/">SourceForge page</a> for releases, documentation, bug-tracking, support
forums and mailing lists.
</td>
</tr>
</table>
<br/>
<table border="0" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td class="textbl" bgcolor="aaaaee" width="50%">Resources</td>
<td class="textbl" bgcolor="aaaaee" width="50%">Requirements</td>
</tr>
</table>
<table border="1" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" bgcolor="eeeeff" class="text" width="50%">
<ul>
<li><a class="textbl" href="http://www.sourceforge.net/projects/phpxmlclasses">Downloads</a>
<li><a class="textbl" href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpxmlclasses/rdql_db/">Browse CVS</a>
<li><a class="textbl" href="http://sourceforge.net/tracker/?atid=470965&group_id=53613&func=browse">Report Bugs</a>
</ul>
</td>
<td valign="top" bgcolor="eeeeff" class="text" width="50%">
<ul>
<li>PHP 4.0.5+
</ul>
</td>
</tr>
</table>
<br/>
<table border="0" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td class="textbl" bgcolor="aaaaee" width="50%">Features</td>
<td class="textbl" bgcolor="aaaaee" width="50%">To-dos</td>
</tr>
</table>
<table border="1" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" bgcolor="eeeeff" class="text" width="50%">
<ul>
<li>Documents are parse before being stored in the database
<li>You can query multiple documents or use * to query all documents in the database
</ul>
</td>
<td valign="top" bgcolor="ddddff" class="text" width="50%">
<ul>
<li>If you have a suggestion please let me know it
</ul>
</td>
</tr>
</table>
<br/>
<table border="0" bgcolor="ddddff" width="80%">
<tr>
<!--
<td valign="top" class="text" width="50%"><b>To-do/future releases:</b>
<ul>
<li>Class
<li>Class
<li>Class
</ul>
</td> -->
<td valign="top" width="100%" class="text">
Contact: <a href="mailto:lrargerich@yahoo.com">Luis Argerich</a>
</td>
</tr>
</table>
<br/>
<table border="0" bgcolor="ddddff" width="80%">
<tr>
<!--
<td valign="top" class="text" width="50%"><b>To-do/future releases:</b>
<ul>
<li>Class
<li>Class
<li>Class
</ul>
</td> -->
<td valign="top" width="100%" class="text">
Detailed description and usage:<br/>
<b>Using the class:</b><br/><br/>
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:
<pre>
mysql foo < rdql_db.sql
</pre>
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:
<pre>
mysql_connect("localhost","root","");
mysql_select_db("foo");
</pre>
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.<br/><br/>
<b>Storing, retrieving and deleting RDF documents</b><br/><br/>
The RDQL_db class let's you store, retrieve and delete documents from the databse, examples:
<pre>
db->store_rdf_document("http://example.com/foo.rdf","foo"); //Store from URL using key=foo
db->remove_rdf_document("foo"); // Eliminate a document
db->get_rdf_document("people"); // Retrieve a document
</pre>
<b>Querying the database</b><br/><br/>
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:
<pre>
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 <a href="rdql.tml">RDQL
tutorial</a> for a description of what can you do with this RDQL implementation.
<br/>
<h3>Documentation</h3>
</div>
<h2>Classes</h2>
<ul>
<li><a href="#class36">RDQL_query_db</a></li>
<li><a href="#class37">RDQL_db</a></li>
<li><a href="#class38">RDF_rdqldb_iterator</a></li>
</ul>
<a name="class36"></a>
<h3>RDQL_query_db</h3>
Extends: None
Description: This class implements the RDQL language for RDF documents stored in a MySQL database using the RDQL_db class.
<br>
<!-- METHOD SUMMARY -->
<A NAME="pDomNode_method_summary"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> array</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class36method1">rdql_query_db</A></B>(string query)</PRE>
<DL>
<DD>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.<DD>
<DL>
<DT><B>Parameters:</B><DD>
query)</CODE>
<BR>
Returns last error message</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class37method2">remove_rdf_document</A></B>(string url, string key)</CODE>
<BR>
Retrieves a document from the database</TD>
</TR>
<!-- A ROW -->
<!-- A ROW -->
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="#class37method5">set_warning_mode</A></B>(boolean key)</PRE>
<DL>
<DD>Removes an RDF document from the database, you have to indicate the document Key to remove it.<DD>
<DL>
<DT><B>Parameters:</B><DD>
url, string url - URL or file-path of the RDF document to be stored<br>key)</PRE>
<DL>
<DD>This method is used to retrieve an RDF document from the database using its key to access the document.<DD>
<DL>
<DT><B>Parameters:</B><DD>
mode)</PRE>
<DL>
<DD>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.<DD>
<DL>
<DT><B>Parameters:</B><DD>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.