I want to print my mysql results to xml. This is what I've tried so far:
include('dbconnect.php');
$sql = "SELECT verse_id, verse_title, verse_content, lang FROM verses WHERE lang = 'English'";
$stmt = $conn->prepare($sql);
$stmt->execute();
$set = array();
while($r = $stmt->fetchAll(PDO::FETCH_ASSOC)){
$set = $r;
}
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($set, array($xml, 'addChild'));
print $xml->asXML();
?>
But it's displaying like this:
<1>verse_id<27>verse_title<"Peace I leave with you; my peace I give you. I do not give to you as the world gives. Do not let your hearts be troubled and do not be afraid. >verse_contentlang<2>
I want to display like this:
<verse>
<verse_id>1</verse_id>
<verse_title>John 3:16</verse_title>
<verse_content>For God so loved the world...</verse_content>
<lang>English</lang>
</verse>
I don't know what's wrong but if you know how to do this and can help, I'd appreciate it.
