domxml_new_docがundefinedと出てしまった。
[vagrant@localhost map]$ php -v
PHP 5.6.27 (cli) (built: Oct 14 2016 14:06:54)
phpのversionは、5.6
php4.0からサポートされているのに何で?と思ったが、以下のようにphp5以上はDOM extensionを使えとのこと。
It will, however, never be released with PHP 5, and will only be distributed with PHP 4. If you need DOM XML support with PHP 5 you can use the DOM extension. This domxml extension is not compatible with the DOM extension.
こちらのDom Object Model
http://us3.php.net/manual/ja/book.dom.php
new DOMDocument(), createElement, appendChild, setAttribute, saveXMLに修正したら問題なく表示されました。
<?php require("phpsqlajax_dbinfo.php"); $doc = new DOMDocument("1.0"); $node = $doc->createElement("makers"); $parnode = $doc->appendChild($node); $connection =mysql_connect('localhost', $username, $password); if (!$connection){ die('Not connected : ' . mysql_error()); } $db_selected = mysql_select_db($database, $connection); if (!$db_selected){ die ('Can\'t use db:' . mysql_error()); } $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if(!$result){ die('Invalid query:' . mysql_error()); } header("Content-type: text/xml"); while ($row = @mysql_fetch_assoc($result)){ $node = $doc->createElement("marker"); $newnode = $parnode->appendChild($node); $newnode->setAttribute("name", $row['address']); $newnode->setAttribute("lat", $row['lat']); $newnode->setAttribute("lng", $row['lng']); $newnode->setAttribute("type", $row['type']); } $xmlfile = $doc->saveXML(); echo $xmlfile; ?>
<makers> <marker name="580 Darling Street, Rozelle, NSW" lat="-33.861034" lng="151.171936" type="restaurant"/> <marker name="76 Wilford Street, Newtown, NSW" lat="-33.898113" lng="151.174469" type="bar"/> <marker name="Greenwood Plaza, 36 Blue St, North Sydney NSW" lat="-33.840282" lng="151.207474" type="bar"/> <marker name="7A, 2 Huntley Street, Alexandria, NSW" lat="-33.910751" lng="151.194168" type="bar"/> <marker name="16 Foster Street, Surry Hills, NSW" lat="-33.879917" lng="151.210449" type="bar"/> <marker name="43 Macpherson Street, Bronte, NSW" lat="-33.906357" lng="151.263763" type="restaurant"/> <marker name="60-64 Reservoir Street, Surry Hills, NSW" lat="-33.881123" lng="151.209656" type="restaurant"/> <marker name="60 Riley Street, Darlinghurst, NSW" lat="-33.874737" lng="151.215530" type="restaurant"/> </makers>