Jump to content

Generate XML file from MYSql


Nandini

Recommended Posts

Hi

 

I want create XML file from mysql table.

 

I have written some script to do that. By using that script xml file was displaying. But database values are not displaying. Here is my script. Can any one tell me where is wrong.

 

<?

$host="localhost";

$dbname="test";

$dbtable="white_list";

$dbuser="root";

$dbpass="";

header("content-type:text/xml");

function getXML($sql="Default Query")

{

$conn=mysql_connect($host,$dbuser,$dbpass);

$db=mysql_select_db($dbname);

$result = mysql_query($sql,$conn);

$columns="";

echo "<records>";

while($row=mysql_fetch_assoc($result))

{

$columns.="<record>";

foreach($row as $key => $value)

{

$columns.="<$key>$value</$key>";

}

$columns.="</record>";

}

echo $columns;

echo "</records>";

}

getXML("SELECT * FROM white_list");

?>

 

Link to comment
https://forums.phpfreaks.com/topic/138198-generate-xml-file-from-mysql/
Share on other sites

I'm not sure if this will work, but worth a go.

 

Try changing your foreach loop with the following.

 

for ($i = 0; $i < mysql_num_fields($result); $i++)
{
$fieldName = mysql_field_name($result, $i);
$columns.="<" . $fieldName . ">" . $row[$fieldName] . "</" . $fieldName . ">";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.