//php将数据库中的内容转换成xml格式的
$db_host="localhost";//数据库位置
$db_user="root"; //用户名
$db_password="123456"; //密码
$db_name="test"; //数据库名称
$link=mysql_connect($db_host,$db_user,$db_password) or die("数据库连接失败");
mysql_query("SET NAMES 'utf8'",$link); //编码utf8
$db=mysql_select_db($db_name,$link);
$table="versionup";//表名
$fic = fopen("version.xml", "w");//输出名称,目录需要有写的权限
fwrite($fic, '<?xml version="1.0" encoding="utf-8"?>');
$xml="";
$elements =array();
$result = mysql_query("describe $table");
while ($row = mysql_fetch_array($result))
$elements[] = $row[0];
$result = mysql_query("select * from $table");
$i = 0;
while ($row = mysql_fetch_array($result)){
$i++;
$xml.="";
for ($j = 0; $j
$xml=$xml.("".htmlspecialchars($row[$j])."$elements[$j]>");
}
$xml=$xml."";
}
$xml=$xml."$table>";
mysql_close();
//$xml= iconv("GBK","UTF-8",$xml);//编码转换
fwrite($fic, $xml);
echo("
");
echo($xml);
fclose($fic);
?>