alt
Advertisement
Sponsored links
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow PHP Oracle arrow Taking Advantage of Standard Internet Protocols
Site Search


Taking Advantage of Standard Internet Protocols
Article Index
Taking Advantage of Standard Internet Protocols
Handling Transactions

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.

  1. <?php
  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.xsd"></employee>
  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. ?>
 
 

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:

  1. CONN xmlusr/xmlusr
  2. SELECT extract(OBJECT_VALUE,'/').getStringVal()
  3. RESULT FROM employees
  4. 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:

  1. <?xml version="1.0"?>
  2. <employee id="304"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:nonamespaceschemalocation="employee.xsd"></employee>
  5. <ename></ename>Polonski
  6. <salary></salary>8200
  7.  
 

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



 
< Prev   Next >
Exforsys Offers
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape