Perlessence

RSS Feeds with daonut

February 12, 2008 08:29

I've recently started work on a database abstraction layer that I call daonut. It's both a learning project as well as a useful utility that I need for building database applications. Ok, I guess I don't need it, but I'm lazy these days and it's easier to make an abstracted call than to manually open the MySQL connection, build and send a query, test for errors, etc. daonut was written based on similar syntax to Gaia's database layer, but with some of the calls tweaked to match my preferences. I didn't look at any of Gaia's code, partially for a learning experience, and partially so I could avoid any copyright issues. I'll have a more detailed post on daonut later, but I wanted to put up a couple examples of the syntax to (hopefully) whet your appetite for more.

include_once '/path/to/daonut/daonut.inc.php';
/* First it's an RSS feed from the internet */
DaoFactory::connect('RSS');
$dao = DaoFactory::create('Feeds.Corkd'); // My Cork'd cellar feed
$dao->execute();
echo "Total rows : " . $dao->affectedrows();
while ($row = $dao->fetchrow()) {
    var_dump($row);
}

/* Now it's a MySQL database */
DaoFactory::connect('MySQL', 'localhost', 'username', 'password');
$dao = DaoFactory::create('Feeds.Corkd'); // table 'corkd' on database 'feeds'
$dao->execute();
echo "Total rows : " . $dao->affectedrows();
while ($row = $dao->fetchrow()) {
    var_dump($row);
}
© Probably a million other people from whom I've subconsciously stolen this layout. Also, Karen Ziv (me). Don't steal my stuff.