getdata.php
资源名称:minierp.rar [点击查看]
上传用户:yantgcom
上传日期:2013-07-19
资源大小:478k
文件大小:1k
源码类别:
MySQL数据库
开发平台:
PHP
- <?
- $gtabname=null;
- $gtabname=$_GET["tn"]; //琛ㄥ悕
- $where=$_GET["where"]; //鏉′欢
- //header("Content-Type:text/xml;charset= UTF-8");
- echo getdatatoxml($gtabname,$where);
- //getdatatoxml($gtabname,$where);
- function getdatatoxml($tbn,$tbw){
- $gtbn=$tbn; //琛ㄥ悕
- $gwh=$tbw; //鏉′欢
- $where= '';
- if (!empty($gwh)) { $where=" where $gwh";}
- include ("../inc/db.php");
- $conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);
- $sSql ="select * from $gtbn $where" ;
- //echo $sSql;
- $fsSql='SHOW COLUMNS FROM '.$gtbn;
- $frs = phpmkr_query($fsSql,$conn) or die("Failed to execute query: " . phpmkr_error() . '<br>SQL: ' . $sSql);
- $rs = phpmkr_query($sSql,$conn) or die("Failed to execute query: " . phpmkr_error() . '<br>SQL: ' . $sSql);
- $xml= "<?xml version="1.0" encoding="UTF-8"?>";
- $xml.= "<root>";
- $field_names = array();
- while($meta = phpmkr_fetch_array($frs)){
- array_push($field_names,$meta[0]);
- }
- while($row = phpmkr_fetch_array($rs)){
- $xml.= '<'.$gtbn.'>';
- //print_r($field_names);
- for($j=0;$j < count($field_names);$j++){
- $xml.= '<'.$field_names[$j].'>'.$row[$j].'</'.$field_names[$j].'>';
- }
- $xml.= '</'.$gtbn.'>';
- }
- $xml.= "</root>n";
- return $xml;
- }
- ?>