Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 need help with rss feeds and MYSQL db

views
     
geekster129
post Jan 18 2009, 06:09 PM

Janitor
******
Senior Member
1,180 posts

Joined: Jan 2007
From: *awaiting GPS accuracy*



First of all, RSS feeds are XML documents in which the contents have certain structures depending on the RSS version.

There are a few questions that you may want to clarify:

1. How do you want to store your RSS feed into the DB? Do you want to store the whole XML raw string into your MySQL field?

2. You want to store certain tags only into a predefined field? E.g. upon new updates detected by your PHP script, then your PHP script will for example take the contents within the <title> and <description> tag for each <item> and perform an SQL Insert into the DB?

Thank you.
geekster129
post Jan 24 2009, 01:39 PM

Janitor
******
Senior Member
1,180 posts

Joined: Jan 2007
From: *awaiting GPS accuracy*



There are 2 strategies to tackle this design.

1. You can store the whole raw XML strings into one of your MySQL field.
2. Break down the tags and categorize them into different field names.

Whatever your strategies are, first of all you would want to "download" the raw XML string from the RSS feed.

You can open a socket connection in your PHP script to the webserver that hosts the RSS feed. The function if I'm not mistaken is called fsockopen();

For example:

This script displays back the XML data retrieved from the server hosting the RSS feed to the client's browser.

CODE

<?php
$fp = fsockopen("rss.forum.lowyat.net", 80, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
   $out = "GET /topic/914049 HTTP/1.1\r\n";
   $out .= "Host: rss.forum.lowyat.net\r\n";
   $out .= "Connection: Close\r\n\r\n";
   fwrite($fp, $out);
   while (!feof($fp)) {
       echo fgets($fp, 128);
   }
   fclose($fp);
}
?>

*Code snippets taken from PHP.net website. Codes value has been modified.



For the MySQL part, that should be quite straight forward. You just need to do an SQL Insert and insert the XML to your MySQL database.

After retrieving the XML string, it will stored into your PHP variable, so you can do whatever you want to it. Be it strategy #1 or strategy #2.

You would also want to schedule a cron job if you're running a Linux/*nix box or the schtasks if you are on Windows to periodically run the PHP script to update your MySQL database with the latest RSS feed.

Thanks

This post has been edited by geekster129: Jan 24 2009, 01:47 PM

 

Change to:
| Lo-Fi Version
0.0138sec    0.29    6 queries    GZIP Disabled
Time is now: 15th December 2025 - 01:49 PM