RSS Feed any MySQL Database using PHP

To some folks rss is this hot new technology that is changing our lives in technology. The truth is rss is a specific formated text file that people finally have standarized on. It’s the standarization that changes people lives, not neccessary the technology. Anyway, a while back I wanted to rss feed our knowledgebase. The knowledgebase articles are stored in a mysql database. I played around with using PEAR::PACKAGE::XML to do the job but found it to be a bit overkill. So I wrote my own xml builder – source code is below or you can download the php rss feed mysql database code. What is nice, is that you can RSS feed any database.

// prepare HTML text for use as UTF-8 character data in XML
function cleanText($intext) {
return utf8_encode(

// set the file's content type and character set
// this must be called before any output
header("Content-Type: text/xml;charset=utf-8");

// retrieve database records

$db = mysql_connect("YourMySQLSERVER", "YOURUSERNAME", "YOURPASSWORD");
if (!$db)
error_log("Error: Could not connect to database in rss.php.");

// store items from the database in the $result1 array

$query1 = "SELECT faqarticles.question, faqarticles.content, SUBSTRING(content,1,600) as mycontent,,, FROM faqarticles WHERE
faqarticles.approved != '1'
$result1 = mysql_query($query1);
$phpversion = phpversion();

// display RSS 2.0 channel information

ECHO << Describe your RSS Feed Heredescription>
PHP/$phpversion 140
Describe Your Image


// loop through the array pulling database fields for each item
for ($i = 0; $i < mysql_num_rows($result1); $i++) {
@$row = mysql_fetch_array($result1);
$title = cleanText($row["question"]);
$link = "".$row["id"];
$description = $row["mycontent"];

//Replace Ugly HTML that got into the Knowledgebase with nothing
$desc_replace = array("


“, “


“, );
$desc_replace_with = array(“”, “”, “”);
$desc_temp = str_replace($desc_replace, $desc_replace_with, $description);

//Now clean the HTML
$mydescription = cleanText($desc_temp);
$pubDate = $row["date"];

// display an item

$link $mydescription… For the entire article, please visit our site.








A .NET, PHP, Marketing Guru authority, at least I hope I am. Reach me at

4 thoughts on “RSS Feed any MySQL Database using PHP

  1. Marc says:

    Wish that code was still up.

  2. sree says:

    i am working with news site. i want rss feed that have the latest vedio news. how to store the rss feed my control pannel please tell me

  3. ipad apps says:

    This code looks very useful, I use my blog test it. Nice features

  4. Hello there folks,
    I am a website specialist attempting to expand my perspectives by learning PHP and mySQL.I have been learning mySQL for a couple of months now by taking after instructional exercises and so on and have a significant decent comprehension of the arrangement now. I have onto adding a mySQL database to my site utilizing PHP (I am still at the beginning phases of learning PHP).

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>