Exforsys

Home arrow Reviews arrow PHP Oracle Training Tutorials

Taking Advantage of Standard Internet Protocols

Page 1 of 2
Author : Exforsys Inc.     Published on: 4th May 2008

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.

Ads

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.

Sample Code
  1. <!--p
  2. //File: uploadXML.php
  3. $host='localhost'
  4. $port=2100
  5. $timeout=30
  6. $db_user='xmlusr'
  7. $db_pswd='xmlusr'
  8. $root_dir='/public/xmlusr/emps'
  9. $empid=304
  10. $file='emp'.$empid.'.xml'
  11. $cnt=
  12. '<?xml version="1.0"?>
  13. <employee id="'.$empid.'"
  14. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
  15. xsi:nonamespaceschemalocation="employee.xs-->
  16. <ename></ename>Polonski
  17. <salary></salary>8200
  18. '
  19. $temp = tmpfile()
  20. fwrite($temp, $cnt)
  21. fseek($temp, 0)
  22. $ftpcon = ftp_connect($host, $port, $timeout)
  23. $login = ftp_login($ftpcon, $db_user, $db_pswd)
  24. ftp_chdir($ftpcon, $root_dir)
  25. ftp_fput($ftpcon, $file, $temp, FTP_ASCII)
  26. ftp_close($ftpcon)
  27. ?>
Copyright exforsys.com


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:

Sample Code
  1. CONN xmlusr/xmlusr
  2. SELECT extract(OBJECT_VALUE,'/').getStringVal()
  3. RESULT FROM employees
  4. WHERE existsNode(OBJECT_VALUE, '/EMPLOYEE/@id="304"') = 1
  5.  
Copyright exforsys.com


If everything is OK, this query should output the employee XML document uploaded by the uploadXML.php script:

Ads

Sample Code
  1. <!--l version="1.0-->
  2. <employee id="304" xsi:nonamespaceschemalocation="employee.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" target="_blank" rel="nofollow"></employee>
  3. <ename></ename>Polonski
  4. <salary></salary>8200
  5.  
  6.  
Copyright exforsys.com


So, after the uploadXML.php script is executed, the XML document inserted by the script becomes permanent immediately.



 
This tutorial is part of a PHP Oracle Training Tutorials tutorial series. Read it from the beginning and learn yourself.

PHP Oracle Training Tutorials

 

Comments