Pear enhance PHP functionality: SQL2XML

Basically PHP5 or above can run smoothly by me.
Prerequisites: PHP5.2 or above
Install: Replace the go-pear.phar content in php/pear directory with http://go-pear.org/
Double click the go-pear.bat  to install PEAR module.
Install XML_Query2XML and MDB2_Driver_mysql packages by dos command: pear install packageName

Moreover,need use the XSL transform function, make sure that uncomment the php_xsl.dll in php.ini


So take a look at the php code.

PHP 代码

  1. <!---->
  2. // include required files   
  3. include 'XML/Query2XML.php';   
  4. include 'MDB2.php';   
  5.   
  6. try {   
  7.     // initalize Query2XML object   
  8.     $q2x = XML_Query2XML::factory(MDB2::factory('mysql://username:password@localhost/databasename'));   
  9.        
  10.     // generate SQL query   
  11.     // get results as XML   
  12.     $sql = "SELECT * FROM Drive";   
  13.     $xml = $q2x->getFlatXML($sql);   
  14.        
  15.     // read XSL stylesheet data   
  16.     $xsl = new DOMDocument;   
  17.     $xsl->load('Drive.xsl');   
  18.        
  19.     // initialize XSLT engine   
  20.     $xslp = new XSLTProcessor;   
  21.        
  22.     // attach XSL stylesheet object   
  23.     $xslp->importStyleSheet($xsl);    
  24.        
  25.     // perform transformation   
  26.     header('Content-Type: text/html');   
  27.     echo $xslp->transformToXML($xml);   
  28. catch (Exception $e) {   
  29.     echo $e->getMessage();   
  30. }   
  31. ?>   

你可能感兴趣的:(sql,mysql,PHP,xml,XSL)