Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2. $username="root";
  3. $password="";
  4. $database="test";
  5.  
  6. // Start XML file, create parent node
  7. $dom = new DOMDocument("1.0");
  8. $node = $dom->createElement("markers");
  9. $parnode = $dom->appendChild($node);
  10.  
  11.  
  12. // Opens a connection to a MySQL server
  13. $connection=mysql_connect ('localhost', $username, $password);
  14. if (!$connection) {
  15. die('Not connected : ' . mysql_error());
  16. }
  17.  
  18. // Set the active MySQL database
  19. $db_selected = mysql_select_db($database, $connection);
  20. if (!$db_selected) {
  21. die ('Can't use db : ' . mysql_error());
  22. }
  23.  
  24. // Select all the rows in the markers table
  25. $query = "SELECT * FROM markers";
  26. $result = mysql_query($query);
  27. if (!$result) {
  28. die('Invalid query: ' . mysql_error());
  29. }
  30.  
  31. header("Content-type: text/xml");
  32.  
  33.  
  34. // Iterate through the rows, adding XML nodes for each
  35. while ($row = @mysql_fetch_assoc($result)){
  36. // ADD TO XML DOCUMENT NODE
  37. $node = $dom->createElement("marker");
  38. $newnode = $parnode->appendChild($node);
  39. $newnode->setAttribute("name", $row['name']);
  40. $newnode->setAttribute("address", $row['address']);
  41. $newnode->setAttribute("lat", $row['lat']);
  42. $newnode->setAttribute("lng", $row['lng']);
  43. $newnode->setAttribute("distance", $row['distance']);
  44. }
  45.  
  46. $smd=$dom->saveXML();
  47. echo $smd;
  48.  
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement