搜索

2

Jun 21, 2016 am 09:09 AM
nbspquotthis

    {
        $this->doXmlString2Xml($string,$xpath);
    }

    /**
    * Adds an additional pear::db_result resultset to $this->xmldoc
    *
    * @param    Object db_result result from a DB-query
    * @see      doSql2Xml()
    * @access   public
    */
    function addResult($result)
    {
        $this->doSql2Xml($result);
    }

    /**
    * Adds an aditional resultset generated from an sql-statement
    *  to $this->xmldoc
    *
    * @param    string sql a string containing an sql-statement.
    * @access   public
    * @see      doSql2Xml()
    */
    function addSql($sql)
    {
        /* if there are {} expressions in the sql query, we assume it's an xpath expression to
        *   be evaluated.
        */

        if (preg_match_all ("/\{([^\}]+)\}/i",$sql,$matches))
        {
            foreach ($matches[1] as $match)
            {
                $sql = preg_replace("#\{".preg_quote($match)."\}#  ", $this->getXpathValue($match),$sql);
            }
        }
        $result = $this->db->query($sql);

        //very strange
        if (PEAR::isError($result->result)) {
                 print "You have an SQL-Error:
".$result->result->userinfo;
                 print "
";
                new DB_Error($result->result->code,PEAR_ERROR_DIE);
        }

        $this->doSql2Xml($result);
    }

    /**
    * Adds an aditional resultset generated from an Array
    *  to $this->xmldoc
    * TODO: more explanation, how arrays are transferred
    *
    * @param    array multidimensional array.
    * @access   public
    * @see      doArray2Xml()
    */
    function addArray ($array)
    {
        $parent_row = $this->insertNewResult(&$metadata);
        $this->DoArray2Xml($array,$parent_row);
    }

    /**
    * Returns an xml-string with a xml-representation of the resultsets.
    *
    * The resultset can be directly provided here, or if you need more than one
    * in your xml, then you have to provide each of them with add() before you
    * call getXML, but the last one can also be provided here.
    *
    * @param    mixed  $result result Object from a DB-query
    * @return   string  xml
    * @access   public
    */
    function getXML($result = Null)
    {
        $xmldoc = $this->getXMLObject($result);
        return $xmldoc->dumpmem();
    }

    /**
    * Returns an xml DomDocument Object with a xml-representation of the resultsets.
    *
    * The resultset can be directly provided here, or if you need more than one
    * in your xml, then you have to provide each of them with add() before you
    * call getXMLObject, but the last one can also be provided here.
    *
    * @param    mixed $result result Object from a DB-query
    * @return   Object DomDocument
    * @access   public
    */
    function getXMLObject($result = Null)
    {
        if ($result) {
            $this->add ($result);
        }
        return $this->xmldoc;
    }

    /**
    * For adding db_result-"trees" to $this->xmldoc
    * @param    Object db_result
    * @access   private
    * @see      addResult(),addSql()
    */
    function doSql2Xml($result)
    {

        if (DB::IsError($result)) {
            print "Error in file ".__FILE__." at line ".__LINE__."
\n";
            print $result->userinfo."
\n";
            new DB_Error($result->code,PEAR_ERROR_DIE);
        }

        // the method_exists is here, cause tableInfo is only in the cvs at the moment
        // BE CAREFUL: if you have fields with the same name in different tables, you will get errors
        // later, since DB_FETCHMODE_ASSOC doesn't differentiate that stuff.
        $this->LastResult = &$result;

        if (!method_exists($result,"tableInfo") || ! ($tableInfo = $result->tableInfo(False)))
        {
            //emulate tableInfo. this can go away, if every db supports tableInfo
            $fetchmode = DB_FETCHMODE_ASSOC;
            $res = $result->FetchRow($fetchmode);
            $this->nested = False;
            $i = 0;

            while (list($key, $val) = each($res))
            {
                $tableInfo[$i]["table"]= $this->tagNameResult;
                $tableInfo[$i]["name"] = $key;
                $resFirstRow[$i] = $val;
                $i++;
            }
            $res  = $resFirstRow;
            $FirstFetchDone = True;
            $fetchmode = DB_FETCHMODE_ORDERED;
        }
        else
        {
            $FirstFetchDone = False;
            $fetchmode = DB_FETCHMODE_ORDERED;
        }

        // initialize db hierarchy...
        $parenttable = "root";
        $tableInfo["parent_key"]["root"] = 0;

        foreach ($tableInfo as $key => $value)
        {
            if (is_int($key))
            {
                // if the sql-query had a function the table starts with a # (only in mysql i think....), then give the field the name of the table before...
                if (preg_match ("/^#/",$value["table"]) || strlen($value["table"]) == 0) {
                     $value["table"] = $tableInfo[($key - 1)]["table"] ;
                    $tableInfo[$key]["table"] = $value["table"];
                }


                if (!isset($tableInfo["parent_table"]) || is_null($tableInfo["parent_table"][$value]["table"]]))
                {
                    $tableInfo["parent_key"][$value]["table"]] = $key;
                    $tableInfo["parent_table"][$value]["table"]] = $parenttable;
                    $parenttable = $value["table"] ;
                }

            }
            //if you need more tableInfo for later use you can write a function addTableInfo..
            $this->addTableInfo($key, $value, &$tableInfo);
        }

        // end initialize

        // if user made some own tableInfo data, merge them here.
        if ($this->user_tableInfo)
        {
            $tableInfo = $this->array_merge_clobber($tableInfo,$this->user_tableInfo);
        }
        $parent['root'] = $this->insertNewResult(&$tableInfo);

        //initialize $resold to get rid of warning messages;
        $resold[0] = "ThisValueIsImpossibleForTheFirstFieldInTheFirstRow";

        while ($FirstFetchDone == True || $res = $result->FetchRow($fetchmode))
        {

            //FirstFetchDone is only for emulating tableInfo, as long as not all dbs support tableInfo. can go away later
            $FirstFetchDone = False;

            while (list($key, $val) = each($res))
            {

                if ($resold[$tableInfo]["parent_key"][$tableInfo][$key]["table"]]] != $res[$tableInfo]["parent_key"][$tableInfo][$key]["table"]]] || !$this->nested)
                {
                    if ($tableInfo["parent_key"][$tableInfo][$key]["table"]] == $key )
                    {
                        if ($this->nested || $key == 0)
                        {

                            $parent[$tableInfo][$key]["table"]] =  $this->insertNewRow($parent[$tableInfo]["parent_table"][$tableInfo][$key]["table"]]], $res, $key, &$tableInfo);
                        }
                        else
                        {
                            $parent[$tableInfo][$key]["table"]]= $parent[$tableInfo]["parent_table"][$tableInfo][$key]["table"]]];
                        }

                        //set all children entries to somethin stupid
                        foreach($tableInfo["parent_table"] as $pkey => $pvalue)
                        {
                            if ($pvalue == $tableInfo[$key]["table"])
                            {
                                $resold[$tableInfo]["parent_key"][$pkey]]= "ThisIsJustAPlaceHolder";
                            }
                        }

                    }
                    if ( $parent[$tableInfo][$key]["table"]] != Null)
                    {
                        $this->insertNewElement($parent[$tableInfo][$key]["table"]], $res, $key, &$tableInfo, &$subrow);
                    }

                }
            }

            $resold = $res;
            unset ($subrow);
        }
        return $this->xmldoc;
    }



    /**
    * For adding whole arrays to $this->xmldoc
    *
    * @param    array
    * @param    Object domNode
    * @access   private
    * @see      addArray()
    */

    function DoArray2Xml ($array, $parent) {

        while (list($key, $val) = each($array))
            {
                $tableInfo[$key]["table"]= $this->tagNameResult;
                $tableInfo[$key]["name"] = $key;
            }

        if ($this->user_tableInfo)
        {
            $tableInfo = $this->array_merge_clobber($tableInfo,$this->user_tableInfo);
        }
        foreach ($array as $key=>$value)
        {
            if (is_array($value) ) {
                if (is_int($key) )
                {
                    $valuenew = array_slice($value,0,1);
                    $keynew = array_keys($valuenew);
                    $keynew = $keynew[0];
                }
                else
                {

                    $valuenew = $value;
                    $keynew = $key;
                }

                $rec2 = $this->insertNewRow($parent, $valuenew, $keynew, &$tableInfo);
                $this->DoArray2xml($value,$rec2);
            }
            else {
                $this->insertNewElement($parent, $array, $key, &$tableInfo,&$subrow);
            }
        }

    }



    /**
    * This method sets the options for the class
    *  One can only set variables, which are defined at the top of
    *  of this class.
    *
    * @param    array   options to be passed to the class
    * @param    boolean   if the old suboptions should be deleted
    * @access   public
    * @see      $nested,$user_options,$user_tableInfo
    */

    function setOptions($options,$delete = False) {
    //set options
        if (is_array($options))
        {
            foreach ($options as $option => $value)
            {
               if (isset($this->{$option}))



声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

北端:融合系统,解释
1 个月前By尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆树的耳语 - 如何解锁抓钩
4 周前By尊渡假赌尊渡假赌尊渡假赌
<🎜>掩盖:探险33-如何获得完美的色度催化剂
2 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。