<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        把從SQL中取出的數據轉化成XMl格式

        來源:懂視網 責編:小采 時間:2020-11-27 19:01:13
        文檔

        把從SQL中取出的數據轉化成XMl格式

        把從SQL中取出的數據轉化成XMl格式: 使用了php的PEAR和DB<php// +----------------------------------------------------------------------+// | PHP version 4.0 |// +-----------------------------------------------------
        推薦度:
        導讀把從SQL中取出的數據轉化成XMl格式: 使用了php的PEAR和DB<php// +----------------------------------------------------------------------+// | PHP version 4.0 |// +-----------------------------------------------------


        使用了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.com/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.com so we can mail you a copy immediately.               
        |// +----------------------------------------------------------------------+
        // | Authors: Christian Stocker <chregu@phant.ch>                         
        |// +----------------------------------------------------------------------+
        //
        // $Id: sql2xml.php,v 1.59 2001/11/13 10::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::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";

            /**
            *
            * @var   object PEAR::DB
            * @access private
            */
            var $db = Null;


            /**
            * 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 some
            *   additional ones. Here they come:
            *  From PEAR::DB->fieldinfo:
            *
            *    $tableInfo[$i]["table"]    : the table, which field #$i belongs to.
            *           for some rdbms/comples queries and with arrays, it's impossible
            *           to find out to which table the field actually belongs. You can
            *           specify it here more accurate. Or if you want, that one fields
            *           belongs to another table, than it actually says (yes, there's
            *           use for that, see the upcoming tutorial ...)
            *
            *    $tableInfo[$i]["name"]     : the name of field #$i. if you want another
            *           name for the tag, than the query or your array provides, assign
            *           it here.
            *
            *   Additional info
            *     $tableInfo["parent_key"][$table]  : index of the parent key for $table.
            *           this is the field, where the programm looks for changes, if this
            *           field changes, it assumes, that we need a new "rowset" in the
            *           parent table.
            *
            *     $tableInfo["parent_table"][$table]: name of the parent table for $table.
            *
            * @var      array
            * @access    private
            */
            var $user_tableInfo = array();

            /**
            * the encoding type, the input from the db has
            */
            var $encoding_from  = "ISO-8859-1";

            /**
            * the encoding type, the output in the xml should have
            * (note that domxml at the moment only support UTF-8, or at least it looks like)
            */
            var $encoding_to = "gb2312";

            var $tagname = "tagname";

            /**
            * Constructor
            * The Constructor can take a Pear::DB "data source name" (eg.
            *  "mysql://user:passwd@localhost/dbname") and will then connect
            *  to the DB, or a PEAR::DB object link, if you already connected
            *  the db before.
            "  If you provide nothing as $dsn, you only can later add stuff with
            *   a pear::db-resultset or as an array. providing sql-strings will
            *   not work.
            * the $root param is used, if you want to provide another name for your
            *  root-tag than "root". if you give an empty string (""), there will be no
            *  root element created here, but only when you add a resultset/array/sql-string.
            *  And the first tag of this result is used as the root tag.
            *
            * @param  mixed $dsn    PEAR::DB "data source name" or object DB object
            * @param  string $root  the name of the xml-doc root element.
            * @access   public
            */
            function XML_sql2xml ($dsn = Null, $root = "root") {

                // if it's a string, then it must be a dsn-identifier;

                if (is_string($dsn))
                {
                    include_once ("DB.php");
                    $this->db = DB::Connect($dsn);
                    if (DB::isError($this->db))
                    {
                        print "The given dsn for XML_sql2xml was not valid in file ".__FILE__." at line ".__LINE__."<br>\n";
                        return new DB_Error($this->db->code,PEAR_ERROR_DIE);
                    }

                }

                elseif (is_object($dsn) && DB::isError($dsn))
                {
                    print "The given param for XML_sql2xml was not valid in file ".__FILE__." at line ".__LINE__."<br>\n";
                    return new DB_Error($dsn->code,PEAR_ERROR_DIE);
                }

                // if parent class is db_common, then it's already a connected identifier
                elseif (get_parent_class($dsn) == "db_common")
                {
                    $this->db = $dsn;
                }

                $this->xmldoc = domxml_new_xmldoc('1.0');

                //oehm, seems not to work, unfortunately.... does anybody know a solution?
                $this->xmldoc->encoding = $this->encoding_to;        

                if ($root) {
                    $this->xmlroot = $this->xmldoc->add_root($root);
                    //PHP 4.0.6 had $root->name as tagname, check for that here...
                    if (!isset($this->xmlroot->{$this->tagname}))
                    {
                        $this->tagname = "name";
                    }
                }

            }

            /**
            * General method for adding new resultsets to the xml-object
            *  Give a sql-query-string, a pear::db_result object or an array as
            *  input parameter, and the method calls the appropriate method for this
            *  input and adds this to $this->xmldoc
            *
            * @param    string sql-string, or object db_result, or array
            * @param    mixed additional parameters for the following functions
            * @access   public
            * @see      addResult(), addSql(), addArray(), addXmlFile()
            */
            function add ($resultset, $params = Null)
            {

                // if string, then it's a query, a xml-file or a xml-string...
                if (is_string($resultset)) {
                    if (preg_match("/\.xml$/",$resultset)) {
                        $this->AddXmlFile($resultset,$params);
                    }
                    elseif (preg_match("/.*select.*from.*/i" ,  $resultset)) {
                        $this->AddSql($resultset);
                    }
                    else {
                        $this->AddXmlString($resultset);
                    }

                }
                // if array, then it's an array...
                elseif (is_array($resultset)) {
                    $this->AddArray($resultset);
                }

                if (get_class($resultset) == "db_result") {
                    $this->AddResult($resultset);
                }
            }

            /**
            * Adds the content of a xml-file to $this->xmldoc, on the same level
            * as a normal resultset (mostly just below <root>)
            *
            * @param    string filename
            * @param    mixed xpath  either a string with the xpath expression or an array with "xpath"=>xpath expression  and "root"=tag/subtag/etc, which are the tags to be inserted before the result
            * @access   public
            * @see      doXmlString2Xml()
            */

            function addXmlFile($file,$xpath = Null)
            {
                $fd = fopen( $file, "r" );
                $content = fread( $fd, filesize( $file ) );
                fclose( $fd );
                $this->doXmlString2Xml($content,$xpath);
            }

            /**
            * Adds the content of a xml-string to $this->xmldoc, on the same level
            * as a normal resultset (mostly just below <root>)
            *
            * @param    string xml
            * @param    mixed xpath  either a string with the xpath expression or an array with "xpath"=>xpath expression  and "root"=tag/subtag/etc, which are the tags to be inserted before the result
            * @access   public
            * @see      doXmlString2Xml()
            */

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        把從SQL中取出的數據轉化成XMl格式

        把從SQL中取出的數據轉化成XMl格式: 使用了php的PEAR和DB<php// +----------------------------------------------------------------------+// | PHP version 4.0 |// +-----------------------------------------------------
        推薦度:
        標簽: 數據庫 腳本 sql
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top 主站蜘蛛池模板: 亚洲一卡2卡4卡5卡6卡在线99| 国产成人精品久久亚洲| 成人免费乱码大片A毛片| 国产真人无遮挡作爱免费视频| 国产婷婷综合丁香亚洲欧洲| 成人无码区免费A片视频WWW| 亚洲午夜精品一区二区公牛电影院 | 韩国免费一级成人毛片| 亚洲国产成人精品无码区在线秒播| 日韩精品人妻系列无码专区免费| 亚洲av日韩av高潮潮喷无码| 亚洲精品免费网站| 成年人视频在线观看免费| 亚洲av无码专区在线观看下载| 国产精品福利在线观看免费不卡| 中文字幕在线亚洲精品| 亚洲国产精品网站在线播放 | 国产精品成人免费视频网站京东| 亚洲自偷自偷在线成人网站传媒 | 亚洲国产精品福利片在线观看| 国产精品白浆在线观看免费| 亚洲自偷精品视频自拍| 精品国产呦系列在线观看免费| 免费无码不卡视频在线观看| 久久久久亚洲AV成人无码| 91久久精品国产免费一区| 亚洲精品成人片在线播放| 日本精品久久久久久久久免费| 亚洲中文字幕日产乱码高清app| 99视频在线看观免费| 亚洲国产欧洲综合997久久| 亚洲伊人久久精品影院| 亚洲黄色免费网站| 亚洲avav天堂av在线不卡| 免费做爰猛烈吃奶摸视频在线观看 | 亚洲AV一二三区成人影片| 全亚洲最新黄色特级网站| 午夜老司机永久免费看片| 亚洲精品久久无码av片俺去也| 亚洲日韩在线观看| 67194熟妇在线永久免费观看|