如何使用PHP将数据从MySQL导出到XML

时间:2013-12-02 10:44:02

标签: php mysql xml export

我有以下PHP代码。如何编辑它以导出到XML? 请帮帮我,我是新手..

<?php
    $koneksi=mysql_connect("localhost","root","");
    mysql_select_db("abdrahmat",$koneksi);
    $id=77;
    $nmtabel="artikel";
    $sql=mysql_query("SELECT * FROM $nmtabel where id_artikel='$id'");
    $r=mysql_fetch_array($sql);// JavaScript Document

1 个答案:

答案 0 :(得分:0)

试试这个:

 $array = json_decode(json_encode($r), true);

 $xml      = new SimpleXMLElement('<root/>');
 $importer = $createArrayImporter($xml);
 echo simplexml_pretty_print($importer($array));