PHP: Generate XML File From MySQL Records
How to generate a XML file from a MySQL database.
Create a database and name is db_toxml. Create a table in the database and name it tbl_mysqltoxml. Now create four fields in the table. The fields are as follows:
xml_tutorial_id: autoinc.
xml_tutorial_title: (varchar - 100)
xml_tutorial_link: (varchar - 250)
xml_tutorial_description: mediumtext
[php]
$dbh=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("db_toxml");
$sql="SELECT * FROM tbl_mysqltoxml ORDER BY xml_tutorial_id DESC LIMIT 0,10";
$results = mysql_query($sql);
$number = mysql_num_rows($results);
$i=0;
while($i < $number){
$lesson = $lesson . "
";
$i++;
}
$file = ('mysqlto.xml');
$fp = fopen($file, "w");
$write = fputs($fp, $news);
fclose($fp);
?>[/php]