Ironvine Analytics Web Analytics, Data Analysis, Online Marketing, and Search Engine Information.

26Sep/06Off

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 . "

" . mysql_result($results, $i, "xml_tutorial_link") . " " . mysql_result($results, $i, "xml_tutorial_description") . "
";
$i++;
}

$file = ('mysqlto.xml');
$fp = fopen($file, "w");
$write = fputs($fp, $news);
fclose($fp);
?>[/php]

Filed under: Code Samples Comments Off
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

No trackbacks yet.