使用了php的PEAR和DB
<?php
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Christian Stocker <chregu@phant.ch> |
// +----------------------------------------------------------------------+
//
// $Id: sql2xml.php,v 1.59 2001/11/13 10:54:02 chregu Exp $
/**
* This class takes a PEAR::DB-Result Object, a sql-query-string or an array
* and returns a xml-representation of it.
*
* TODO
* -encoding etc, options for header
* -ERROR CHECKING
*
* Usage example
*
* include_once ("DB.php");
* include_once("XML/sql2xml.php");
* $db = DB::connect("mysql://root@localhost/xmltest");
* $sql2xml = new xml_sql2xml();
* //the next one is only needed, if you need others than the default
* $sql2xml->setEncoding("ISO-8859-1","UTF-8");
* $result = $db->query("select * from bands");
* $xmlstring = $sql2xml->getXML($result);
*
* or
*
* include_once ("DB.php");
* include_once("XML/sql2xml.php");
* $sql2xml = new xml_sql2xml("mysql://root@localhost/xmltest");
* $sql2xml->Add("select * from bands");
* $xmlstring = $sql2xml->getXML();
*
* More documentation and a tutorial/how-to can be found at
* http://php.chregu.tv/sql2xml
*
* @author Christian Stocker <chregu@bitflux.ch>
* @version $Id: sql2xml.php,v 1.59 2001/11/13 10:54:02 chregu Exp $
* @package XML
*/
class XML_sql2xml {
/**
* If joined-tables should be output nested.
* Means, if you have joined two or more queries, the later
* specified tables will be nested within the result of the former
* table.
* Works at the moment only with mysql automagically. For other RDBMS
* you have to provide your table-relations by hand (see user_tableinfo)
*
* @var boolean
* @see $user_tableinfo, doSql2Xml(), doArray2Xml();
*/
var $nested = True;
/**
* Name of the tag element for resultsets
*
* @var string
* @see insertNewResult()
*/
var $tagNameResult = "result";
/**
* Name of the tag element for rows
*
* @var string
* @see insertNewRow()
*/
var $tagNameRow = "row";
/**
* Options to be used in extended Classes (for example in sql2xml_ext).
* They are passed with SetOptions as an array (arrary("user_options" = array());
* and can then be accessed with $this->user_options["bla"] from your
* extended classes for additional features.
* This array is not use in this base class, it's only for passing easy parameters
* to extended classes.
*
* @var array
*/
var $user_options = array();
/**
* The DomDocument Object to be used in the whole class
*
* @var object DomDocument
* @access private
*/
var $xmldoc;
/**
* The Root of the domxml object
* I'm not sure, if we need this as a class variable....
* could be replaced by domxml_root($this->xmldoc);
*
* @var object DomNode
* @access private
*/
var $xmlroot;
/**
* This array is used to give the structure of your database to the class.
* It's especially useful, if you don't use mysql, since other RDBMS than
* mysql are not able at the moment to provide the right information about
* your database structure within the query. And if you have more than 2
* tables joined in the sql it's also not possible for mysql to find out
* your real relations.
* The parameters are the same as in fieldInfo from the PEAR::DB and