i've made an rss reader using PHP and all my database is stored in MySQL. the problem is, i don't know how to store RSS feeds into MySQL database. can anybody please help me? thx.
need help with rss feeds and MYSQL db
need help with rss feeds and MYSQL db
|
|
Jan 18 2009, 03:25 PM, updated 17y ago
Show posts by this member only | Post
#1
|
![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
1,895 posts Joined: Jan 2003 From: Shah Alam |
i've made an rss reader using PHP and all my database is stored in MySQL. the problem is, i don't know how to store RSS feeds into MySQL database. can anybody please help me? thx.
|
|
|
|
|
|
Jan 18 2009, 06:09 PM
Show posts by this member only | Post
#2
|
![]() ![]() ![]() ![]() ![]() ![]()
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. |
|
|
Jan 19 2009, 11:38 AM
Show posts by this member only | Post
#3
|
![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
1,895 posts Joined: Jan 2003 From: Shah Alam |
thx for the reply.
well the reason why i would want to store the rss feed is mainly because when there's no internet connection, the rss reader will read the feeds from the database. the database will not store all the rss read but maybe 4-6 feeds. since my reader reads not only the title but also the content of the news so i expect to store the entire content. currently the rss feed is store in my browser cache but i would like it to store in my MySQL database too. |
|
|
Jan 19 2009, 11:47 AM
Show posts by this member only | Post
#4
|
|
Elite
4,956 posts Joined: Jan 2003 |
Erm, what's the point? Its not like you can get an updated list without an internet connection, and if your RSS reader has already read the feed and updated your list, the content should be available to you already.
|
|
|
Jan 20 2009, 09:47 PM
Show posts by this member only | Post
#5
|
![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
1,895 posts Joined: Jan 2003 From: Shah Alam |
well, it's just as a backup IF there's no internet connection suddenly. well, i just want to know how do i code it.
|
|
|
Jan 24 2009, 01:22 PM
Show posts by this member only | Post
#6
|
![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
1,895 posts Joined: Jan 2003 From: Shah Alam |
any1 care to help? pls
|
|
|
Jan 24 2009, 01:39 PM
Show posts by this member only | Post
#7
|
![]() ![]() ![]() ![]() ![]() ![]()
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 |
|
|
Jan 24 2009, 02:05 PM
Show posts by this member only | Post
#8
|
![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
1,895 posts Joined: Jan 2003 From: Shah Alam |
geekster129 : thx bro, i will give this a try and inform here the result.
anyways, if any1 else do have another method pls tell. thx |
| Change to: | 0.0148sec
1.18
5 queries
GZIP Disabled
Time is now: 14th December 2025 - 10:04 AM |