Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. <?php
  2.  
  3. require 'config.php';
  4. require 'array2xml.php';
  5.  
  6. //get username and password
  7. $config = new Config();
  8.  
  9. $user = $config->getUser();
  10. $pass = $config->getPass();
  11.  
  12. //create connection object
  13. try {
  14.  
  15. $dbc = new PDO('mysql:host=localhost;dbname=StudentDB',
  16. $user, $pass);
  17. echo 'Connection established <br>';
  18. }
  19.  
  20. catch(PDOException $e) {
  21. echo "An error occured while connecting to database: "
  22. . $e->getMessage();
  23. }
  24.  
  25. $sql = $dbc->query('SELECT * FROM student');
  26.  
  27. $result = $sql->fetchALL(PDO::FETCH_CLASS);
  28.  
  29. echo "<pre>" . print_r($result, true) . "<pre/>";
  30.  
  31. echo "<br>";
  32. echo "<br>";
  33.  
  34. //create object of class capable of conversion
  35. $convert = new Array2XML();
  36.  
  37. $xml = $convert::createXML("Student", $result);
  38.  
  39. $xmlstring = $xml->saveXML();
  40.  
  41. echo "<pre>" . $xmlstring . "<pre/>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement