<?php
header('Access-Control-Allow-Origin: *');
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/xml');

$dbh = new PDO("mysql:host=localhost;dbname=tasks", "root", "gc01mysql");
$dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);

$q = $dbh->query("SELECT kunde, system, plz, ort FROM kunden");
$cust = $q->fetchAll(PDO::FETCH_ASSOC);

$doc = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\" />");

foreach($cust as $c) {
	$p = $doc->addChild("Placemark");
	$p->addChild("name", $c['kunde']);
	$p->addChild("description", $c['system']);
	$point = $p->addChild("Point");
	$point->addChild("coordinates", "-122.0822035425683,37.42228990140251,0");
}
echo $doc->asXML();