Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2.  
  3. $server = 'localhost';
  4. $user='root';
  5. $pass='';
  6. $db='cdkatalog';
  7. try {
  8. $con=new mysqli($server,$user,$pass,$db) or die("Greska!");
  9. } catch (Exception $exc) {
  10. echo $exc->getTraceAsString();
  11. }
  12. $sql='select * from cd';
  13. $rezultat = $con->query($sql);
  14. $xml = new DOMDocument('1.0');
  15. $xml->formatOutput = true;
  16. $catalog = $xml->createElement('CATALOG');
  17. $xml->appendChild($catalog);
  18.  
  19. while($row=$rezultat->fetch_assoc()){
  20. $cd = $xml->createElement('CD');
  21. $cd->setAttribute("id", $row['id']);
  22. $catalog->appendChild($cd);
  23.  
  24. $title=$xml->createElement('TITLE', $row['title']);
  25. $cd->appendChild($title);
  26.  
  27. $artist=$xml->createElement('ARTIST', $row['artist']);
  28. $cd->appendChild($artist);
  29.  
  30.  
  31. $country=$xml->createElement('COUNTRY', $row['country']);
  32. $cd->appendChild($country);
  33.  
  34. $company=$xml->createElement('COMPANY', $row['company']);
  35. $cd->appendChild($company);
  36.  
  37.  
  38. $price=$xml->createElement('PRICE', $row['price']);
  39. $cd->appendChild($price);
  40.  
  41.  
  42. $year=$xml->createElement('YEAR', $row['year']);
  43. $cd->appendChild($year);
  44. }
  45.  
  46. $xml->saveXML();
  47. $xml->save("xmlFROMdb.xml");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement