Reviews
PHP Oracle Training TutorialsTaking Advantage of Standard Internet Protocols
Taking Advantage of Standard Internet Protocols
As mentioned, Oracle XML DB provides native support for standard internet protocols, such as HTTP(S), WebDAV, and FTP. Continuing with the preceding sample, you might, for example, upload another employee XML document into the XML repository with one of the above protocols, say, FTP.
NOTE: Starting with Oracle Database 10g Release 2, FTP is disabled by default, for security reasons. This is achieved by setting the FTP port to 0. To enable FTP, you must manually set the FTP port number to an appropriate value, such as 2100, which is the default value in Oracle Database releases before 10g Release 2. Changing the FTP port to an appropriate value can be easily done with the help of Oracle Enterprise Manager, a graphical tool supplied with Oracle Database. For more information on Oracle Enterprise Manager, refer to Oracle documentation: chapter Getting Started with Oracle Enterprise Manager in the Oracle Database 2 Day DBA manual.
The uploadXML.php script shown below provides a simple example of how you might upload an XML document into the XML repository through FTP protocol.
- <!--p
- //File: uploadXML.php
- $host='localhost'
- $port=2100
- $timeout=30
- $db_user='xmlusr'
- $db_pswd='xmlusr'
- $root_dir='/public/xmlusr/emps'
- $empid=304
- $file='emp'.$empid.'.xml'
- $cnt=
- '<?xml version="1.0"?>
- <employee id="'.$empid.'"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
- xsi:nonamespaceschemalocation="employee.xs-->
- <ename></ename>Polonski
- <salary></salary>8200
- '
- $temp = tmpfile()
- fwrite($temp, $cnt)
- fseek($temp, 0)
- $ftpcon = ftp_connect($host, $port, $timeout)
- $login = ftp_login($ftpcon, $db_user, $db_pswd)
- ftp_chdir($ftpcon, $root_dir)
- ftp_fput($ftpcon, $file, $temp, FTP_ASCII)
- ftp_close($ftpcon)
- ?>
In the above script, you start by setting up the parameters required to connect to the FTP server running on the database server.
By including the value of the employee's id attribute in the name of the XML file to be uploaded into the XML repository, you ensure the uniqueness of file names within the repository folder that contains employee XML documents in single files.
Then, you create a temp file and write XML content in it. Then, you connect to the Oracle FTP server and upload the fi le into the XML repository. After the uploadXML.php script is executed, to make sure that the employee XML
document has been successfully uploaded into the XML repository, you might issue the following query from SQL*Plus:
- CONN xmlusr/xmlusr
- SELECT extract(OBJECT_VALUE,'/').getStringVal()
- RESULT FROM employees
- WHERE existsNode(OBJECT_VALUE, '/EMPLOYEE/@id="304"') = 1
If everything is OK, this query should output the employee XML document uploaded by the uploadXML.php script:
- <!--l version="1.0-->
- <employee id="304" xsi:nonamespaceschemalocation="employee.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" target="_blank" rel="nofollow"></employee>
- <ename></ename>Polonski
- <salary></salary>8200
So, after the uploadXML.php script is executed, the XML document inserted by the script becomes permanent immediately.
PHP Oracle Training Tutorials
- PHP Oracle Web Development
- XML Processing in PHP and Oracle Applications
- Creating XML with the DOM PHP Extension
- Querying a DOM Document with XPath
- Transforming and Processing XML with XSLT
- Performing XML Processing inside the Database
- Moving All the XML Processing into the Database
- Performing XSLT Transformations inside the Database
- Using Oracle Database for Storing, Modifying, and Retrieving XML Data
- Using XMLType for Handling XML Data in the Database
- Using XML Schemas
- Retrieving XML Data
- Using XMLType Views
- Performing DML Operations on XML Schema Based XMLType Views
- Using Oracle XML DB Repository
- Accessing Repository Resources with SQL
- Taking Advantage of Standard Internet Protocols
- Querying Data with Oracle XQuery
- Breaking up XML into Relational Data







