溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請您在轉(zhuǎn)載時注明出處http://www.aygfsteel.com/sxyx2008/謝謝合作!!!

          雪山飛鵠

          溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請您在轉(zhuǎn)載時注明出處http://www.aygfsteel.com/sxyx2008/謝謝合作!!!

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
          amfphp下載:http://sourceforge.net/projects/amfphp/files/amfphp/
          這里我們下載amfphp 1.9.zip
          下載后解壓到web服務(wù)器的工作目錄下,前提是您已配置好php的工作環(huán)境。這里為了簡單起見,使用IIS7.0+php5.2
          即:將amfphp1.9解壓到C:\inetpub\wwwroot
          browser:目錄為amfphp可供我們直接在瀏覽器瀏覽的目錄
          services:目錄是我們自己開發(fā)的php類文件存放目錄
          gateway.php是一個比較重要的文件。
          打開gateway.php,定位到127行
          //$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");
          $gateway->setCharsetHandler("utf8_decode", "utf-8", "utf-8");
          設(shè)置中文字符支持
          如果服務(wù)器和php環(huán)境正常的話,在地址欄輸入http://localhost/amfphp/browser/將會看到如下圖所示
          配置參數(shù)如上圖所示,點save保存設(shè)置。
          編寫一個php與mysql交互的類。
          product.php
          <?php
          class product{

              
          function print_xml(){
              
          //獲取數(shù)據(jù)庫連接
                  $link=@mysql_connect("localhost","root","") or die('數(shù)據(jù)庫連接錯誤');
                  
          //選擇數(shù)據(jù)庫
                  mysql_select_db("compass",$link);
                  
          //設(shè)置數(shù)據(jù)庫編碼
                  mysql_query("set names utf8",$link);
                  
          //查詢數(shù)據(jù)庫
                  $result=mysql_query("select * from product");
                  
                  
          //創(chuàng)建DOMDocument對象
                  $doc = new DOMDocument('1.0','utf-8');
                  
          //格式化輸出
                  $doc->formatOutput = true;
                  
                  
          //創(chuàng)建根元素
                  $root = $doc->createElement('root');
                  
          //添加根元素
                  $root = $doc->appendChild($root);
              
                  
          //從數(shù)據(jù)庫中獲取數(shù)據(jù)每一條是一個product
                  while($data=mysql_fetch_assoc($result)){
                      
                      
          //創(chuàng)建product標(biāo)簽
                      $product=$doc->createElement('product');
                      
          //添加product標(biāo)簽
                      $product = $root->appendChild($product);

                      
          //創(chuàng)建Id元素
                      $id = $doc->createElement('id');
                      
          //添加Id
                      $id = $product->appendChild($id);
                      
          //創(chuàng)建文本內(nèi)容
                      $idtext = $doc->createTextNode($data['id'].'');
                      
          //將文本添加到id標(biāo)簽內(nèi)
                      $idtext = $id->appendChild($idtext);
                 
                      
          //創(chuàng)建name標(biāo)簽
                      $name = $doc->createElement('name');
                      
          //添加name
                      $name = $product->appendChild($name);
                      
          //創(chuàng)建name標(biāo)簽的文本
                      $nametext = $doc->createTextNode($data['name'].'');
                      
          //設(shè)置name標(biāo)簽的文本
                      $nametext = $name->appendChild($nametext);

                      
          //創(chuàng)建price標(biāo)簽
                      $price = $doc->createElement('price');
                      
          //添加price
                      $price = $product->appendChild($price);
                      
          //創(chuàng)建price標(biāo)簽的文本
                      $pricetext = $doc->createTextNode($data['price'].'');
                      
          //設(shè)置price標(biāo)簽的文本
                      $pricetext = $price->appendChild($pricetext);
                  }
                  
          //關(guān)閉數(shù)據(jù)庫連接
                  mysql_close($link);
                  
          //保存xml
                  return $doc->saveXML();
              }
          }
          ?>

          注意該文件的編寫規(guī)則及存放路徑
          php中類文件的編寫符合java中類的編寫,即文件名與類名大小寫一致
          該文件必須存放于C:\inetpub\wwwroot\amfphp\services\目錄下
          方法最后使用return 返回而不是輸出
          http://localhost/amfphp/browser/中的瀏覽情況
          posted on 2011-10-28 11:18 雪山飛鵠 閱讀(2825) 評論(0)  編輯  收藏 所屬分類: flex+php
          主站蜘蛛池模板: 随州市| 仲巴县| 两当县| 海口市| 宣威市| 琼结县| 宜黄县| 乌审旗| 青川县| 泰顺县| 曲靖市| 通州区| 抚顺县| 高青县| 罗甸县| 凤凰县| 紫阳县| 沛县| 龙游县| 衢州市| 兴和县| 苏尼特右旗| 巨野县| 靖安县| 彩票| 民丰县| 仪陇县| 东平县| 五大连池市| 阿鲁科尔沁旗| 镇宁| 昭平县| 徐州市| 雅江县| 柳河县| 新丰县| 马公市| 饶河县| 电白县| 通渭县| 东乡|