Murphy1976
Murphy1976

Reputation: 1475

Updating a database automatically from a RSS Feed

I'm looking to update a MySQL database with items from an RSS Feed. When the RSS Feed gains a new item, it is automatically fed into the MySQL database.

I have a php page that connects to the database and inserts data into, and i also have a PHP RSS parser, but I'm not certain on how to connect them so that when there is a new item in the RSS Feed, it runs the PHP script and inserts that item into the database.

Upvotes: 2

Views: 3215

Answers (3)

Harry
Harry

Reputation: 344

I need more information about your DB connector and RSS parser... what db API you use is it PDO MySQLi or something else? Are you able to parse rss and store data from it in array or in objects.

you can create a insert query and store in it data from objects or arrays like this:

$q = "INSERT INTO `my_table_name` (`id`, `name`, `etc`) VALUES (NULL, '$data->name', '$data->etc')";

Upvotes: 0

Jeremy Harris
Jeremy Harris

Reputation: 24549

The best way is to schedule a cron job that runs a PHP script to check if a new RSS feed exists. You can set a time interval to run this script (1 hour, 1 day, etc).

If it finds new data, you run it through your parser, and pass the data to your database. Here is some psuedo code:

// Get RSS data new today
$rssFeed = getNewRssFeeds('today');

if($rssfeed)
{
   // Parse feed into an array of data
   $dataArray = $myRssParser->parse($newRSS);

   // Insert into DB
   $myDbHandler->insert($dataArray);
}

None of those functions are real, you would have to code them. But that is generally how it could work.

Upvotes: 3

Joshua Martell
Joshua Martell

Reputation: 7212

You can setup a cron job to retrieve data periodically from the RSS feed and push updates into the database.

Upvotes: 0

Related Questions