Tutorials
PHP OracleWhen building XML-enabled applications on top of Oracle, there are many advantages to performing the XML processing inside the database when compared to performing it on the client. The key advantages to perform XML processing inside the database are as follows:
Moving XML processing to the database may be especially useful if you are dealing with large XML documents stored in the database. In that case, your application won't need to transfer a large amount of data between the database and web server when processing XML inside the database?only the final product is sent across the wire.
The simplest way to benefit from moving XML processing to the database is to use Oracle SQL/XML functions, which allow you to build SQL queries generating XML from relational data.
Turning back to the preceding sample, you might, for example, rewrite the query issued against the database so that it retrieves the generated employees XML document that is ready to be transformed into HTML with the PHP XSL extension functions.
Diagrammatically, this might look like the following figure:

The explanation of the steps in the figure is the following:
In this scenario, you move some XML processing from the web server to the database server. In particular, the XML document is now generated on the database server with the help of the SQL/XML generation functions specified in the query, rather than generating that document on the web server with the PHP DOM extension functions as it was in the scenario depicted in the figure shown in the Transforming and Processing XML with XSLT section earlier in this chapter.
The following listing contains the SQLXMLQuery.php script that implements the above scenario. So, the script issues the query that makes Oracle generate the employees XML document, thus retrieving the employees XML document that is ready to be transformed with XSLT. The following script provides an example of using Oracle SQL/XML functions to generate XML from relational data. Using these functions lets you move the processing required to generate the employees XML document from the web server to the database server.
As you can see, the SQLXMLQuery.php script, unlike the DOM.php script discussed earlier in this chapter, does not use the PHP DOM functions to generate the employees XML document from scratch, based on the result set retrieved from the database. Instead, it issues a query that instructs the database server to generate that XML document. After executing the query, you fetch the result of the query and then load it to the newly created DOM document.
Next, you load the employees.xsl XSL stylesheet discussed in the Transforming and Processing XML with XSLT section earlier, assuming that this fi le resides in the same directory where you saved the SQLXMLQuery.php script discussed here.
Then, you create an XSLT processor, in which you import the employees.xsl stylesheet loaded into a DOM document. After performing the XSL transformation, you print the resultant HTML page.
When you run the SQLXMLQuery.php script, it should output a page that looks like the one shown in the figure in the Transforming and Processing XML with XSLT section.