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

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

  5. really such an impressive and knowledgeable post, RSS solves a problem for people who regularly use the web. It allows you to easily stay informed by retrieving the latest content from the sites you are interested in. You save time by not needing to visit each site individually. and I love to use the RSS but recently I have to face some difficulties in my web project but after your post it really the reason for my solution.

  6. What is nice, is that you can RSS feed any database.

  7. This is such a tremendous and useful post. I appreciate this content and also the writer of this article. Thanks for sharing in public. Keep improve.

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>