Advertisement
klt2127

phpajaxsql_genxml.php

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