当前位置: 首页 > 图文教程 > 网络编程 > PHP > 二 php与XML、XSLT、Mysql的结合运用,代码篇

PHP
MYSQL版本大于4.1问题 - PHPchina
怎么让用户点击一个连接后,把一个图片另存了 - PHPchina
武汉10月15日Phper聚会召集!!! - PHPchina
php如果不等待exec执行的程序创建的子进程? - PHPchina
哪位知道DISCUZ处理防SQL注入的代码是哪部分 - PHPchina
求教!我实在不知道哪里问题,在线等ing - PHPchina
怎样结束用户某一进程 - PHPchina
比对用户名密码能不能这样写? - PHPchina
求助:如何在PHP+mysql中实现数据备份? - PHPchina
大家看看这个配置对吗 - PHPchina
如何禁止require当前文件 - PHPchina
无法将回调函数放在类中? - PHPchina
村里 PHP代码高亮是怎么实现的? - PHPchina
apache安装后.服务里没有apache2这个服务! - PHPchina
请教一个小问题 - PHPchina
config.php里面是不是应该把多数参数设置为常量而不是变量? - PHPchina
请教高手一个问题 - PHPchina
如何让百度收录我的网站 ?? - PHPchina
谁能给个注入的简单语句? - PHPchina
求PHP站内搜索思路 - PHPchina

PHP 中的 二 php与XML、XSLT、Mysql的结合运用,代码篇


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 82 ::
收藏到网摘: n/a

<?php    
    require_once "DB.php";            //PEAR中的数据库处理类
    $dataType = "mysql" ;            //数据库类型
    $user = "root";                    //用户名
    $pass = "abcd" ;                //密码
    $host="202.96.215.200";            //Mysql数据库服务器地址
    $db_name = "test";                //数据库名
    $dsn="$dataType://$user:$pass@$host/$db_name";   //连接数据库的DNS配制
    $db = DB::connect($dsn);        //连接数据库
    if (DB::isError($db))
    {            
        die ($db->getMessage());    //连接失败,输出出错信息
    }
    
    //下面二个是公共的函数
    /**
     * 读取xsl文档
     *
     * @param String $filename - xsl文件的名称
     * @return string
     */
    function readXsl($filename)
    {    
        if(false==file_exists($filename))
        {
            echo "要读取的文件<font color='red'>$filename</font>不存在</br />";    
            return false    ;
        }
        return implode('', file($filename));
    } //end function readXsl

/**
* 将xml文件或数组变量根据xsl文件转换成HTML内容
*
* @param array $arydata - 数组变量
* @param String $xslstring - xsl文档数据
* @param String $xmlstring - xml文档数据
*/
function getHtml($arydata = false, $xslstring = false, $xmlstring = false)
{
    global $db ;    //使用刚才的$db对象
    include_once("XML/sql2xml.php");    //把sql2xml包含进来
    $sql2xmlclass = new xml_sql2xml($db);    //将sql2xml实例化
    $sql2xmlclass->setEncoding("GB2312");    //设置数据的转码类型
    if (false == $xmlstring) { // 如果用户传入数组数据,则应用该数组数据到xsl        
        //设置生成XML文档数据的节点名称
        $options = array (  tagNameRow      => "row" ,
                            tagNameResult   => "result"