title: how to create xml file using php and mysql?
body: <p>I am trying to make a xml file from the data stored in my local db using php. But i am having a problem with it. as when I hard code the value I am able to get the xml file but when i am trying to call from the database i am not able to do it? so can some one help me out with it.</p>
  
  <p>so here is the code that i wrote..</p>
  
  <pre><code>&lt;?php
  
   include 'config.php';
   include 'database.php';
  
  $sql = "select title, content, url from table limit 100";
  $results = Database::GetAll($sql);
  
  $xml = new DomDocument("1.0","UTF-8");
  
  $content = $xml-&gt;createElement("content");
  $content = $xml-&gt;appendChild($content);
  
  foreach($results as $result) {
      $item = $xml-&gt;createElement("item");
      $item = $content-&gt;appendChild($item);
  
      $title = $xml-&gt;createElement("title",$result['title']);
      $title = $item-&gt;appendChild($title);
  
      $description = $xml-&gt;createElement("description",$result['content']);
      $description = $item-&gt;appendChild($description);
  
      $link = $xml-&gt;createElement("link",htmlspecialchars($result['url']));
      $link = $item-&gt;appendChild($link);
  }
  
  $xml-&gt;FormatOutput = true;
  $output = $xml-&gt;saveXML();
  $xml-&gt;save("xmls.xml");
  
  
  ?&gt;
  </code></pre>
  
  <p>here Database::GetAll($sql) is a class that i have created, it executes the query and gets the table contents. the <strong>config</strong> file consists of all the database credentials and <strong>database.php</strong> is the file with the class of database.</p>
  
  <p>The XML that i would want is</p>
  
  <pre><code>&lt;content&gt;
  &lt;item&gt;
  &lt;title&gt;....&lt;/title&gt;
  &lt;description&gt;....&lt;/description&gt;
  &lt;url&gt;....&lt;/url&gt;
  &lt;/item&gt;
  
  &lt;item&gt;
  &lt;title&gt;....&lt;/title&gt;
  &lt;description&gt;....&lt;/description&gt;
  &lt;url&gt;....&lt;/url&gt;
  &lt;/item&gt;
  
  &lt;item&gt;
  &lt;title&gt;....&lt;/title&gt;
  &lt;description&gt;....&lt;/description&gt;
  &lt;url&gt;....&lt;/url&gt;
  &lt;/item&gt;
  
  ...till 100 values..
  &lt;/content&gt;
  </code></pre>
  
  <p>here the <strong>....</strong> between the tags represent the datas retrieved from the database using mysql.
   <strong>var_dump($results)</strong> gives me all the three required values upto the 100th row.</p>
  
  <p>and these are the errors that I am getting while using my code..</p>
  
  <pre><code> Warning: DOMDocument::createElement(): unterminated entity reference loc=hpa1&amp;icid=hpa1_bestofsale_010715 in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference locale=en_US&amp;repriceOrder=true in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference subCatView=true&amp;adcell=hpmemberjeans in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference deptId=dept20000020&amp;subcatId=cat1003450012&amp;N=1003070048&amp;extDim=true&amp;cm_re=S2-_-CAT-_-SPORT_WATCHES in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference ab=HP_BSpot_B4_40OffFootwear in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference pid=8672,8541,8532,8699,107705,8664,8806,8539,8808,8540,8826,8828,8542,104632,107703,8827&amp;sortExpression=manual&amp;heig in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference cm_sp=LN-_-Save+Up+to+75%25+Off+Select+Items++-_-Up+to+50%25+Off+Select+Body+Care&amp;cp=4090263.46772866 in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference CP=ILC-FLASH:20offShoes&amp;sortmfr=N in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference pid=8672,8541,8532,8699,107705,8664,8806,8539,8808,8540,8826,8828,8542,104632,107703,8827&amp;sortExpression=manual&amp;heig in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference so=2 in C:\xampp\htdocs\practice\d\xmls.php on line 23
  
  Warning: DOMDocument::createElement(): unterminated entity reference node=10470257011&amp;smid=ATVPDKIKX0DER&amp;pf_rd_m=ATVPDKIKX0DER&amp;pf_rd_t=701&amp;pf_rd_s=center-3&amp;pf_rd_r=0ZC491KTZNEXXHNV96NM&amp;pf_rd_i=30&amp;pf in C:\xampp\htdocs\practice\d\xmls.php on line 23
  </code></pre>
  
  <p>updated xml file output as displayed..</p>
  
  <pre><code>This page contains the following errors:
  
  error on line 2 at column 3431: Encoding error
  Below is a rendering of the page up to the first error.
  
   Free shipping on orders worth $99 at LogoSportswearFree shipping on orders worth $99 at LogoSportswearhttp://www.logosoftwear.com/Save up to 75% on sale styles at loft.comGet a discount up to 75% on sale styles at loft.comhttp://www.loft.com/nfp-sale-cat-091312/cat1100006?supCat=catl00008&amp;loc=hpa1&amp;icid=hpa1_bestofsale_010715Free shipping on orders worth $200 or more at lechateau.comFree shipping on orders worth $200 or more at lechateau.comhttp://www.lechateau.com/style/index.jsp?storeId=334&amp;locale=en_US&amp;repriceOrder=trueSave up to 65% on outer wear at landsend.comGet a discount up to 65% on outer wear at landsend.comhttp://www.landsend.com/Free precious set with purchase worth $130 at loccitane.comFree precious set with purchase worth $130 at loccitane.com. Use the coupon code to avail the offer.http://usa.loccitane.com/precious-skin,82,1,65481,673013.htm#xcms_position=05_precious#xcms_campaign=shop_now_&gt;Save 15% when you spend under $100 at kohls.comGet a discount of 15% when you spend under $100 at kohls.com. Use the coupon code to avail the offer.http://www.kohls.com/Save 10% on denim for the family at kmart.comGet a discount of 10% on denim for the family at kmart.comhttp://www.kmart.com/clothing-shoes-jewelry-specialty-shops-jeans-shop/b-1339616014?filter=storeOrigin&amp;subCatView=true&amp;adcell=hpmemberjeansSave up to 30% on dinner ware at kirklands.comGet a discount up to 30% on dinner ware at kirklands.comhttp://www.kirklands.com/category/Kitchen-Dining/Dinnerware/pc/2753/2681.uts?icid=hppromo5010115Save up to 50% on cargo pants at kingsizedirect.comGet a discount up to 50% on cargo pants at kingsizedirect.comhttp://www.kingsizedirect.com/Big-and-Tall-Cargo-Pants.aspx?DeptId=23955Free shipping on orders worth $75 at justmysizeFree shipping on orders worth $75 at justmysizehttp://www.hanes.com/justmysizeFree shipping site wide on all US orders at jomashop.comFree shipping site wide on all US orders at jomashop.com. Use the coupon code to avail the offer.http://www.jomashop.com/Save 20% on watches at jcpenney.comGet a discount of 20% on watches at jcpenney.com. Use the coupon code to avail the offer.http://www.jcpenney.com/jewelry-watches/watches/all-watches/cat.jump?id=cat100240089&amp;deptId=dept20000020&amp;subcatId=cat1003450012&amp;N=1003070048&amp;extDim=true&amp;cm_re=S2-_-CAT-_-SPORT_WATCHESSave up to 60% on coats at jackthreads.comGet a discount up to 60% on coats at jackthreads.comhttps://www.jackthreads.com/sales/coats-are-up-to-60-off/15162
  </code></pre>
  
  <p>so how can i get this? </p>
  
  <p>thank you</p>