I’m trying to dynamically output regions within a country from the database to create markers on a google map, and am following a tutorial and its exactly how they want me to do it but its not working for me.
I get an error and no xml output.
<?php
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Select all the rows in the markers table
$query = "SELECT Nom_Rsrt, lat, lng, IdCntry_Rsrt FROM tbl_resorts WHERE (IdCntry_Rsrt=".$selectCountry.")";
$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 = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
//$newnode->setAttribute("name",$row['name']);
$newnode->setAttribute("address", $row['Nom_Rsrt']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
//$newnode->setAttribute("type", $row['type']);
}
echo $dom->saveXML();
?>
And this is the error I’m getting
Warning: DOMElement::setAttribute(): string is not in UTF-8 in \CSFFILES11\WEBSITES\dev\new_checksafetyfirst\en\result.php on line 125 Warning: DOMElement::setAttribute(): string is not in UTF-8 in \CSFFILES11\WEBSITES\dev\new_checksafetyfirst\en\result.php on line 125 Warning: DOMElement::setAttribute(): string is not in UTF-8 in \CSFFILES11\WEBSITES\dev\new_checksafetyfirst\en\result.php on line 125 Warning: DOMElement::setAttribute(): string is not in UTF-8 in \CSFFILES11\WEBSITES\dev\new_checksafetyfirst\en\result.php on line 125 Warning: DOMElement::setAttribute(): string is not in UTF-8 in \CSFFILES11\WEBSITES\dev\new_checksafetyfirst\en\result.php on line 125 Warning: DOMDocument::saveXML(): output conversion failed due to conv error, bytes 0xE1 0x64 0x69 0x7A in \CSFFILES11\WEBSITES\dev\new_checksafetyfirst\en\result.php on line 131
I’m not sure what going wrong as the code seems perfectly fine to me
Ok it seems the last error is unrelated and have cleared up th eothers, and change the code as above, but I’m still not getting any xml outputting to the browser
<!-- Start of Google Map API -->
<?php
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Select all the rows in the markers table
$query = mysql_query("SELECT Nom_Rsrt, lat, lng, IdCntry_Rsrt FROM tbl_resorts WHERE (IdCntry_Rsrt='".$selectCountry."')");
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = mysql_fetch_assoc($query)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("address", utf8_encode($row['Nom_Rsrt']));
$newnode->setAttribute("lat", utf8_encode($row['lat']));
$newnode->setAttribute("lng", utf8_encode($row['lng']));
}
echo $dom->saveXML();
?>
It does though seem to be gathering the info from the database correctly as I used var_dump($row) in the while loop and I got the following output which is correct
Are you sure you want to use p(ersistent)connect here?
mysql_pconnect() acts very much like mysql_connect() with two major differences.
First, when connecting, the function would first try to find a (persistent) link that’s already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).
i.e. persistent does not mean “please don’t go away on me” it means “stick around I’ll be using you again”
Persistent connection support was introduced in PHP 5.3 for the mysqli extension. Support was already present in PDO MYSQL and ext/mysql.
I agree that spending any time on patching up old DEPRECATED mysql_ code is a waste of time.
But AFAIK (I’ve never used them) persistent connections are still supported.