ACC
ACC

Reputation: 2570

Dump SQLite query result to XML

I am trying to query a SQLite DB and dump the result to xml. Here is the code:

    $db = new SQLite3("terrapin");
$db->exec($insert);

$select = "select * from information";
$results=$db->query($select);
while($result=$results->fetchArray(SQLITE3_ASSOC))
{
        $xml.="<username>".$result['username']."</username>\n";
        $xml.="<latitude>".$result['latitude']."</latitude>\n";
        $xml.="<longtitude>".$result['longtitude']."</longtitude>\n";
        $xml.="<timestamp>".$result['timestamp']."</timestamp>\n";
        $xml.="<filename>".$result['filename']."</filename>\n";
}

When I do a print_r($xml), PHP prints out all values but does not show tags. I am trying to use the code from here. What am I missing?

Upvotes: 0

Views: 782

Answers (1)

Aurimas Ličkus
Aurimas Ličkus

Reputation: 10074

Because tags is interpreted as html tags so you wont see them, view source to see them. What you need to do is provide

<?xml version="1.0"?>

And send correct response headers to browser that its xml to HTML

header ("Content-Type:text/xml");
echo $xml;
exit;

Also you are missing root element.

Upvotes: 1

Related Questions