Christians Aggregator update.php
require_once('rss.php');
$db = mysql_connect('localhost', 'cb', 'cb');
mysql_select_db('cb', $db);
$sql = 'SELECT id, RSS, Title FROM feeds';
$q = mysql_query($sql, $db);
$rss = new FliquidRSS();
$rss->setMaxResults(5);
while ($row = mysql_fetch_assoc($q)) {
// Lets get the feed:
$rss->newURL($row['RSS']);
$rss->parseRSS();
foreach($rss->xmlarray as $k => $v) {
// We need to escape anything that might trip up mysql
foreach ($rss->xmlarray[$k] as $key => $val) {
$rss->xmlarray[$k][$key] = $val;
}
}
$feed = urlencode(serialize($rss->xmlarray));
$updatesql = "UPDATE feedcontents SET FeedData='".$feed."' WHERE FeedID = ".$row['id'];
mysql_query($updatesql, $db);
if (mysql_affected_rows($db) == 0) {
$insertsql = "INSERT INTO feedcontents VALUES (".$row['id'].", '".$feed."')";
if (mysql_query($insertsql, $db)) {
print "Inserted " . $row['Title'] . "";
} else {
print "There was a problem inserting the records for " . $feed['Title'] . "";
print "The error was: " . mysql_error() . "";
}
} else {
print "Updated " . $row['Title'] . "";
}
}
