clh899 发表于 2017-3-22 08:48:35

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.
InstallXML_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 代码

[*]<!---->
[*]// include required files   
[*]include 'XML/Query2XML.php';   
[*]include 'MDB2.php';   
[*]  
[*]try {   
[*]    // initalize Query2XML object   
[*]    $q2x = XML_Query2XML::factory(MDB2::factory('mysql://username:password@localhost/databasename'));   
[*]       
[*]    // generate SQL query   
[*]    // get results as XML   
[*]    $sql = "SELECT * FROM Drive";   
[*]    $xml = $q2x->getFlatXML($sql);   
[*]       
[*]    // read XSL stylesheet data   
[*]    $xsl = new DOMDocument;   
[*]    $xsl->load('Drive.xsl');   
[*]       
[*]    // initialize XSLT engine   
[*]    $xslp = new XSLTProcessor;   
[*]       
[*]    // attach XSL stylesheet object   
[*]    $xslp->importStyleSheet($xsl);    
[*]       
[*]    // perform transformation   
[*]    header('Content-Type: text/html');   
[*]    echo $xslp->transformToXML($xml);   
[*]} catch (Exception $e) {   
[*]    echo $e->getMessage();   
[*]}   
[*]?>   
页: [1]
查看完整版本: Pear enhance PHP functionality: SQL2XML