public static function testStories(MySQLDB $db = NULL)
 {
     if ($db === NULL) {
         $db = self::$site_db;
     }
     try {
         // MySQLFeed::get stories test (relies on MySQLFeed::create)
         $feed = MySQLFeed::create(self::$feedinfo, $db);
         $db->pdo->exec("INSERT INTO feed_stories\n\t\t    (title, content, url, time_stamp, sid, gid)\n\t\t     VALUES ('MySQLTest_title', 'MySQLTest_content',\n                             'MySQLTest_storyurl', " . time() . ",\n                             " . $feed->sid . ", 1);");
         $db->pdo->exec("INSERT INTO feed_stories\n\t\t    (title, content, url, time_stamp, sid, gid)\n\t\t     VALUES ('MySQLTest_title2', 'MySQLTest_content2',\n                             'MySQLTest_storyurl', " . time() . ",\n                             " . $feed->sid . ", 1);");
         $get_feedinfo = $feed->get(array('stories'), $db);
         $stories = $get_feedinfo['stories'];
         if ($get_feedinfo === NULL) {
             throw new Exception('MySQLFeed::get stories test failed');
         }
         // MySQLStories foreach test
         foreach ($stories as $story) {
             if (!$story instanceof MySQLStory) {
                 throw new Exception('MySQLStories foreach test failed');
             }
         }
         foreach ($stories as $story) {
             // MySQLStory::find test
             $find_story = MySQLStory::find('fid', $story->fid, $db);
             if ($find_story === NULL || $find_story->fid != $story->fid) {
                 throw new Exception('MySQLFeed::find test failed');
             }
             // MySQLStory::get test
             $get_storyinfo = $story->get(array('url'));
             if ($get_storyinfo['url'] != 'MySQLTest_storyurl') {
                 throw new Exception('MySQLStory::get test failed');
             }
             // MySQLStory::__get test
             $get_name = $story->get(array('content'));
             if ($story->content !== $get_name['content']) {
                 throw new Exception('MySQLStory::__get test failed');
             }
             $db->pdo->exec("DELETE FROM feed_stories WHERE fid={$story->fid};");
             /* XXX if this line is added and "SELECT * FROM feed_stories WHERE 
             	 url='MySQLTest_storyurl';" is run from the same system in the 'mysql'
             	 program, then the stories are not deleted below! */
             //throw new Exception();
         }
         $feed->delete();
     } catch (Exception $e) {
         if (isset($feed)) {
             $db->pdo->exec("DELETE FROM feed_stories WHERE sid={$feed->sid};");
             $feed->delete();
         }
         throw $e;
     }
 }
 public static function __create(array $feedinfo, MySQLDB $db)
 {
     // parse $feedinfo into a format able to be fed straight into database
     $db_feedinfo = self::parseFeedInfo($feedinfo, $db);
     // build the SQL query to use to replace the feed
     $create_sql = 'INSERT IGNORE INTO feed_sources (';
     // add column names
     foreach ($db_feedinfo as $col => $value) {
         $create_sql .= $col . ', ';
     }
     // remove trailing comma and space
     $create_sql = substr($create_sql, 0, -2);
     // add column values
     $create_sql .= ') VALUES (';
     foreach ($db_feedinfo as $col => $value) {
         $create_sql .= ':' . $col . ', ';
     }
     // remove trailing comma and space
     $create_sql = substr($create_sql, 0, -2);
     $create_sql .= ');';
     // prepare the SQL statement
     $create_stmt = $db->pdo->prepare($create_sql);
     // bind column values
     foreach ($db_feedinfo as $col => $value) {
         $create_stmt->bindValue(':' . $col, $value);
     }
     // execute the SQL statement
     $create_stmt->execute();
     return MySQLFeed::find('url', $feedinfo['url'], $db);
 }