public static function testFeed(MySQLDB $db = NULL) { try { // MySQLFeed::create test $feed = MySQLFeed::create(self::$feedinfo, $db); if ($feed === NULL) { throw new Exception('MySQLFeed::create test failed'); } // MySQLFeed::find test $find_feed = MySQLFeed::find('name', self::$feedinfo['name'], $db); if ($find_feed === NULL) { throw new Exception('MySQLFeed::find test failed'); } // MySQLFeed::delete test $feed->delete(); unset($feed); $deleted_feed = MySQLFeed::find('name', self::$feedinfo['name'], $db); if ($deleted_feed !== NULL) { throw new Exception('MySQLFeed::delete test failed'); } // MySQLFeed::get test $feed = MySQLFeed::create(self::$feedinfo, $db); $get_feedinfo = $feed->get(array_keys(self::$feedinfo)); if ($get_feedinfo != self::$feedinfo) { throw new Exception('MySQLFeed::get test failed'); } // MySQLFeed::__get test $get_name = $feed->get(array('name')); if ($feed->name !== $get_name['name']) { throw new Exception('MySQLFeed::__get test failed'); } $feed->delete(); } catch (Exception $e) { if (isset($feed)) { $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); }