Some of the google php example code does not work in php 5 dot something.
And also you might find this map stuff certainly wont work properly in the versions of Firefox that exist at the time of this post. Something to do with ajax I believe. This code fixes that.
Over the years, lots of people hunting down fatal errors like:
undefined function: domxml_open_mem() or
Call to undefined function domxml_new_doc()
and its evident they are trying to make work the same sample code that I have. (The correct code is now on the google site btw)
The problem might be that they are using the wrong version of code with the release of PHP they have installed. The internet has been sending people down the wrong tracks trying to solve the problem.
It is also apparent that 5.x of PHP has, by default, the modules available for handling php.
Some basic checks first before moving onto the code:
To get it working in Centos you need to have libxml2.x86_64 0:2.6.26-2.1.2.6 libxml2.i386 0:2.6.26-2.1.2.6
which means yum install libxml2
You should check the modules dir, e.g. /usr/lib64/php/modules/ for the presence of dom.so
Look at your php.ini (usually in /etc)
extension=dom.so
may not be necessary, errors like
PHP Warning: Module ‘mysql’ already loaded in Unknown on line 0 that appear when trying to run code from the command line may occur because in /etc/php.d/mysql.ini the module is already declared and subsequently loaded, therefore you can edit out the extentions = section of your /etc/php.ini
I’ve butchered the code of Google to suit my own application and table def. The critical lines changed are
$doc = new DOMDocument(‘1.0′); (was create_document)
$node = $doc->createElement …. (was create_element)
$doc->appendChild($node) … (was append_child)
$newnode->setAttribute(“… (was set_attribute)
$xmlfile = $doc->saveXML($markers_node); (was dump_mem)
<?php
require(“./phpsqlajax_dbinfo.php”);
// Start XML file, create parent node
$doc = new DOMDocument(‘1.0′);
$markers_node = $doc->createElement(“markers”);$parnode = $doc->appendChild($node);
//markers_node is a node we’ll need as part of the FF fix. Basically somehow an extra line gets inserted which contains whitespace which leads to the error, Error: XML or text declaration not at start of entity. It will still work in IE though.
// Opens a connection to a mySQL server
$connection=mysql_connect ($mysql_host, $mysql_login, $mysql_pass);
if (!$connection) {
die(‘Not connected : ‘ . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($mysql_db, $connection);
if (!$db_selected) {
die (‘Can\’t use db : ‘ . mysql_error());
}
// Select all the rows in the markers table
$query = “SELECT * FROM ch_points WHERE 1″;
$result = mysql_query($query);
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}
header(“Content-type: text/xml”);
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $doc->createElement(“marker”);
$newnode = $parnode->appendChild($node);
$newnode->setAttribute(“name”, $row['owner']);
$newnode->setAttribute(“address”, $row['postcode']);
$newnode->setAttribute(“lat”, $row['lat']);
$newnode->setAttribute(“lng”, $row['lon']);
$newnode->setAttribute(“type”, $row['phases']);
}
$xmlfile = $doc->saveXML($markers_node);
//This is the other part of the firefox fix. Just pump out the nodes we need via markers_node.
echo $xmlfile;
?>