Skip to main content
Known Participant
March 16, 2011
Question

Dynamic XML from PHP and MySQL

  • March 16, 2011
  • 1 reply
  • 685 views

Hi,

I'm learning php and I'm trying to get to grips with dynamic xml and php  coming from a database.  The trouble I am having is I can't get my code  to give any output.  I don't get an error I message, I just can't get  the xml to display.  If anyone can give me any pointers as to what I'm  doing wrong that would be great...

Here's the code I have.


<?php  

DEFINE
('DB_USER', 'root');

DEFINE ('DB_PASSWORD', 'password');

DEFINE ('DB_HOST', 'localhost');

DEFINE ('DB_NAME', 'flashphpbible'); 



$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);



$query = "SELECT * FROM dynamicxml WHERE id=1";

$result = mysqli_query($link, $query); 

$xmlData .= " ";

$xmlData .= "<store>\n";  



while(
$row = mysqli_fetch_array($result));

{    

$xmlData .= " <item>\n";    

$xmlData .= "     <name>".$row['name']."</name>\n";     $xmlData .= "     <section>".$row['section']."</section>\n";     $xmlData .= "     <price>".$row['price']."</price>\n";

$xmlData .= "     <inStock>".$row['instock']."</inStock>\n";     $xmlData .= " </item>\n"





$xmlData .= "</store>\n";  echo "response=".$xmlData; ?>

Thanks for any help offered.
Ben.

This topic has been closed for replies.

1 reply

Günter_Schenk
Inspiring
March 16, 2011

Can´t help with your specific issue, but in my opinion the PHP version of the "Query to XML" sample code posted on Adobe Labs is much easier to follow respectively adapt for PHP debutants, and it will also add something important which your code doesn´t: a correct XML header.