Migrating old code from API 1 to API 1.1


Apologies if this has been asked many times before, but when API 1 was up and running I used this code to save Tweets to an SQL database (which came from http://www.inkplant.com/code/pull-twitter-feed-into-your-site.php), which used the “search.atom” command:

require_once 'db-functions.inc.php' ; //custom database functions

function saveTweets($hash_tag) {
global $link;

if (!$hash_tag) { echo "Error: No hash tag declared.n"; return false; }

$row = dbGetRow("SELECT `id` FROM `tags` WHERE `author`='$author' ORDER BY `id` DESC LIMIT 1");
$last_id = $row['id'];

$url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag). 


if ($last_id) { $url .= "&since_id=$last_id" ; }
$ch = curl_init($url);
$xml = curl_exec ($ch);
curl_close ($ch);

$affected = 0;
$twelement = new SimpleXMLElement($xml);
foreach ($twelement->entry as $entry) {
$text = trim($entry->title);
$author = trim($entry->author->name);
$time = strtotime($entry->published);
$id = $entry->id;

dbQuery("INSERT IGNORE INTO `tags` (`id`,`author`,`time`,`text`,`hidden`) 

VALUES ('".dbEscape($id)."','".dbEscape($author)."','$time','".dbEscape


$affected = $affected + dbAffectedRows();

//return "<p>".number_format($affected)." new tweets from $hash_tag saved.</p>" ;

echo saveTweets('@Twitter');
echo saveTweets('@TFL');
echo saveTweets('@CentralLine');
echo saveTweets('@tfltrafficnews');
echo saveTweets('#tfl');
echo saveTweets('#londonbuses');
echo saveTweets('#tube');

Obviously in the API 1.1 era the RSS feed has now been turned off, and code now needs Oauth.
Yes, I’ve migrated over to 140Dev to store Tweets (so have the relevant keys), but as I already have the databases in place, what code would need to be added/changed to make the code work again?
I’ve tried using the some of the 140Dev code and libraries with little success, so thanks for any help (and apologies if it has been asked before).