//class Feed, Feed.php
<?php
require_once('Db.php');

Class 
Feed {

Function 
GetHeader(){

return 
"<?xml version=\"1.0\"?>
<rss version=\"2.0\">
<channel>
<title>Example</title>
<description>This is an example site</description>
<link>http://www.theexamplesite.com</link>
<language>en-us</language>"
;

}

Function 
GetBody() {
$db = new Db();
$db->GetFeedData();
$strBody"";
for(
$i=0$i<sizeof($db->arData); $i++){

$desc=$db->arData["desc"][$i];
$time=$db->arData["time"][$i];
$id=$db->arData["id"][$i];
$heading $db->arData["heading"][$i];

$strBody$strBody "
<item>
<title>
$heading</title>
<description>
$desc</description>
<link>http://www.theexamplesite.com/blog.php?id=
$id</link>
<pubDate>
$time</pubDate>
<guid>http://www.theexamplesite.com/blog.php?id=
$id</guid>
</item>"
;

}
return 
$strBody;
}

Function 
GetFooter(){

  return 
"
</channel>
</rss>"
;
}

Function 
CreateFeed(){

$file fopen("feed.xml""w");

fwrite($file$this->GetHeader());

fwrite($file$this->GetBody());

fwrite($file$this->GetFooter());

fclose($file);

}

}

?> // end class Feed


//class Db, Db.php
<?php

class Db {

public 
$arData;

function 
__construct()
{
mysql_connect('localhost''user''password');
mysql_select_db('dbname');
}

Public function 
GetFeedData(){

$select_sql "SELECT postid, heading, description,
timestamp from post order by postid DESC limit 15"
;

$result mysql_query($select_sql);

$num_rows mysql_num_rows($result);

if(!
$result || ($num_rows 0)) {
      die(
"error : " mysql_error() );
}

if(
$num_rows == 0){
     echo 
"Database table empty";
        exit;
        return;
   }

 for(
$i=0$i<$num_rows$i++){
  
$this->arData["id"][$i]=mysql_result($result,$i,"postid");
  
$this->arData["heading"][$i]=mysql_result($result,$i,"heading");
  
$this->arData["desc"][$i]=mysql_result($result,$i,"description");
  
$this->arData["time"][$i] = $this->FormatDate(
  
mysql_result($result,$i,"timestamp"),"D, j M Y H:i:00 O");

}
}


function 
FormatDate($dtDbDate$strDateFormat){

//leave numbers only in date
$dtDbDate ereg_replace('[^0-9]'''$dtDbDate);

//extract date and time components
$strSecond substr($dtDbDate,12,2);
$strMinute substr($dtDbDate,10,2);
$strHour substr($dtDbDate,8,2);
$strDay substr($dtDbDate,6,2);
$strMonth substr($dtDbDate,4,2);
$strYear substr($dtDbDate,0,4);

//Get date format for feed
$dtNewFormat date($strDateFormatmktime($strHour,
 
$strMinute$strSecond$strMonth$strDay$strYear));
return 
$dtNewFormat;
}

}
?> // end class Db