温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

雪山飞鹄

温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

BlogJava 首页 新随笔 联系 聚合 管理
  215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
function print_xml(){
    
//获取数据库连接
        $link=@mysql_connect("localhost","root","") or die('数据库连接错误');
        
//选择数据库
        mysql_select_db("compass",$link);
        
//设置数据库编码
        mysql_query("set names utf8",$link);
        
//查询数据库
        $result=mysql_query("select * from product");
        
        
//创建DOMDocument对象
        $doc = new DOMDocument('1.0','utf-8');
        
//格式化输出
        $doc->formatOutput = true;
        
        
//创建跟元素
        $root = $doc->createElement('root');
        
//添加跟元素
        $root = $doc->appendChild($root);
    
    
//从数据库中获取数据每一条是一个product
        while($data=mysql_fetch_assoc($result)){
      
//创建Id元素
            $id = $doc->createElement('id');
            
//添加Id
            $id = $root->appendChild($id);
            
//创建文本内容
            $idtext = $doc->createTextNode($data['id'].'');
            
//将文本添加到id标签内
            $idtext = $id->appendChild($idtext);
       
      
//创建name标签
            $name = $doc->createElement('name');
            
//添加name
            $name = $root->appendChild($name);
            
//创建name标签的文本
            $nametext = $doc->createTextNode($data['name'].'');
            
//设置name标签的文本
            $nametext = $name->appendChild($nametext);

      
//创建price标签
            $price = $doc->createElement('price');
            
//添加price
            $price = $root->appendChild($price);
            
//创建price标签的文本
            $pricetext = $doc->createTextNode($data['price'].'');
            
//设置price标签的文本
            $pricetext = $price->appendChild($pricetext);
        }
        
//关闭数据库连接
        mysql_close($link);
        
//保存xml
        echo $doc->saveXML();
    }
posted on 2011-10-27 10:33 雪山飞鹄 阅读(676) 评论(0)  编辑  收藏 所属分类: flex+php

只有注册用户登录后才能发表评论。


网站导航: