From 41986bbc783f007c79df1b508942809a742876d2 Mon Sep 17 00:00:00 2001 From: canyonknight Date: Fri, 25 May 2012 17:45:53 -0400 Subject: rss.php: Pull out DB code * Move DB code in rss.php to new function in aur.inc.php * Centralization of DB code important in a future transition to PDO interface Signed-off-by: canyonknight Signed-off-by: Lukas Fleischer --- web/html/rss.php | 8 ++------ web/lib/aur.inc.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'web') diff --git a/web/html/rss.php b/web/html/rss.php index c7de4c65..6f057bfe 100644 --- a/web/html/rss.php +++ b/web/html/rss.php @@ -37,13 +37,9 @@ $image->description = "AUR Newest Packages Feed"; $rss->image = $image; #Get the latest packages and add items for them -$dbh = db_connect(); -$q = "SELECT * FROM Packages "; -$q.= "ORDER BY SubmittedTS DESC "; -$q.= "LIMIT 20"; -$result = db_query($q, $dbh); +$packages = latest_pkgs(20); -while ($row = mysql_fetch_assoc($result)) { +while (list($indx, $row) = each($packages)) { $item = new FeedItem(); $item->title = $row["Name"]; $item->link = "{$protocol}://{$host}/packages.php?ID={$row["ID"]}"; diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 1a294a93..4e6baa2d 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -533,3 +533,22 @@ function last_insert_id($dbh=NULL) { } return mysql_insert_id($dbh); } + +function latest_pkgs($numpkgs, $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + } + + $q = "SELECT * FROM Packages "; + $q.= "ORDER BY SubmittedTS DESC "; + $q.= "LIMIT " .intval($numpkgs); + $result = db_query($q, $dbh); + + if ($result) { + while ($row = mysql_fetch_assoc($result)) { + $packages[] = $row; + } + } + + return $packages; +} -- cgit v1.2.3-24-g4f1b