daily pastebin goal
86%
SHARE
TWEET

Untitled

a guest Feb 4th, 2016 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $servername = "localhost";
  3. $username = "mikeb";
  4. $password = "password";
  5. $dbname = "my_mikeb";
  6. $room = $_GET['room'];
  7.  
  8.  
  9. // Create connection
  10. $conn = mysqli_connect($servername, $username, $password, $dbname);
  11. // Check connection
  12. if (!$conn) {
  13.     die("Connection failed: " . mysqli_connect_error());
  14. }
  15.  
  16. $xml = new XMLWriter();
  17.  
  18. $xml->openURI("php://output");
  19. $xml->startDocument('1.0" encoding="UTF-8');
  20. $xml->setIndent(true);
  21.  
  22. $xml->startElement('players');
  23.  
  24. $sql = "SELECT id, name, attack , level FROM $room";
  25. $result = mysqli_query($conn, $sql);
  26.  
  27. if (mysqli_num_rows($result) > 0) {
  28.     // output data of each row
  29.     while($row = mysqli_fetch_assoc($result)) {
  30.         //echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["attack"]. "<br>";
  31.        
  32.           $xml->startElement("player");
  33.  
  34.              $xml->writeAttribute('id', $row['id']);
  35.                   $xml->startElement("name");
  36.                     $xml->writeRaw($row['name']);
  37.                   $xml->endElement();
  38.                   $xml->startElement("attack");      
  39.                     $xml->writeRaw($row['attack']);
  40.                     $xml->endElement();
  41.                     $xml->startElement("level");      
  42.                     $xml->writeRaw($row['level']);
  43.                   $xml->endElement();
  44.  
  45.           $xml->endElement();
  46.     }
  47. } else {
  48.     echo "0 results";
  49. }
  50. $dom = new DomDocument('1.0', 'UTF-8');
  51. $dom->save('players.xml');
  52. mysqli_close($conn);
  53.  
  54.  
  55. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top