diff --git a/actions/ad_actions.install b/actions/ad_actions.install
index 9a44d94..57bffb9 100644
--- a/actions/ad_actions.install
+++ b/actions/ad_actions.install
@@ -67,7 +67,7 @@
  * ad_actions module installation.
  */
 function ad_actions_install() {
-  drupal_install_schema('ad_actions');
+  //drupal_install_schema('ad_actions');
 }
 
 /**
@@ -75,6 +75,6 @@
  */
 function ad_actions_uninstall() {
   // Remove tables.
-  drupal_uninstall_schema('ad_actions');
+  //drupal_uninstall_schema('ad_actions');
 }
 
diff --git a/actions/ad_actions.module b/actions/ad_actions.module
index 4734b62..2b65618 100644
--- a/actions/ad_actions.module
+++ b/actions/ad_actions.module
@@ -27,7 +27,7 @@
 function ad_actions_cron() {
   // if time, send queued notification emails
   $result = db_query('SELECT qid, context FROM {ad_actions_queue} WHERE period >= 0 AND scheduled <= %d', time());
-  while ($notify = db_fetch_object($result)) {
+  while ($notify = $result->fetch()) {
     db_query('DELETE FROM {ad_actions_queue} WHERE qid = %d', $notify->qid);
     _ad_actions_send_email(unserialize($notify->context));
   }
@@ -48,7 +48,7 @@
   // if time, send queued "autoactivated" and "autoexpired" notification emails
   if (!empty($activate) || !empty($expire)) {
     $result = db_query('SELECT qid, aid, period, context FROM {ad_actions_queue} WHERE sent = 0 AND period < 0');
-    while ($notify = db_fetch_object($result)) {
+    while ($notify = $result->fetch()) {
       if (isset($expire[$notify->aid])) {
         // minus a minus is a plus...
         if ((time() - $notify->period) >= $expire[$notify->aid]) {
@@ -145,7 +145,7 @@
  */
 function ad_actions_send_email_action_before($object, $context) {
   if ($context['before']) {
-    if (!db_result(db_query_range("SELECT 1 FROM {ad_actions_queue} WHERE aid = %d AND period = %d AND recipient = '%s'", $object->aid, $context['before'], $context['recipient'], 0, 1))) {
+    if (!db_query_range("SELECT 1 FROM {ad_actions_queue} WHERE aid = %d AND period = %d AND recipient = '%s'", $object->aid, $context['before'], $context['recipient'], 0, 1)->fetchField()) {
       db_query("INSERT INTO {ad_actions_queue} (aid, recipient, period, scheduled, context) VALUES(%d, '%s', %d, %d, '%s')", $object->aid, $context['recipient'], $context['before'], time() + $context['before'], serialize($context));
       watchdog('action', 'Queued email for scheduled trigger to %recipient', array('%recipient' => $context['recipient']));
     }
@@ -192,7 +192,7 @@
 function ad_actions_send_email_action_after($object, $context) {
   if ($context['after']) {
     // send delayed notification email
-    if (!db_result(db_query_range("SELECT 1 FROM {ad_actions_queue} WHERE aid = %d AND period = %d AND recipient = '%s'", $object->aid, $context['after'], $context['recipient'], 0, 1))) {
+    if (!db_query_range("SELECT 1 FROM {ad_actions_queue} WHERE aid = %d AND period = %d AND recipient = '%s'", $object->aid, $context['after'], $context['recipient'], 0, 1)->fetchField()) {
       db_query("INSERT INTO {ad_actions_queue} (aid, recipient, period, scheduled, context) VALUES(%d, '%s', %d, %d, '%s')", $object->aid, $context['recipient'], $context['after'], time() + $context['after'], serialize($context));
       watchdog('action', 'Queued email to %recipient', array('%recipient' => $context['recipient']));
     }
@@ -381,7 +381,7 @@
     $field = '';
     $result = db_query('SELECT category, name, title FROM {profile_fields}');
     $first = TRUE;
-    while ($row = db_fetch_object($result)) {
+    while ($row = $result->fetch()) {
       if ($first) {
         $fields = array('-1' => '- '. t('select a profile field') .' -');
         $first = FALSE;
diff --git a/ad.admin.inc b/ad.admin.inc
index 1f55ec9..349afa3 100644
--- a/ad.admin.inc
+++ b/ad.admin.inc
@@ -45,7 +45,7 @@
 
   $destination = drupal_get_destination();
   $ads = array();
-  while ($ad = db_fetch_object($result)) {
+  while ($ad = $result->fetch()) {
     $ads[$ad->aid] = '';
     $form['title'][$ad->aid] = array('#value' => l($ad->title, 'node/'. $ad->aid));
     $form['group'][$ad->aid] = array('#value' => _ad_get_group($ad->aid));
@@ -140,7 +140,7 @@
   $form['ads'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
   // array_filter returns only elements with TRUE values
   foreach (array_filter($form_state['post']['ads']) as $aid => $value) {
-    $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $aid));
+    $title = db_query('SELECT title FROM {node} WHERE nid = %d', $aid)->fetchField();
     $form['ads'][$aid] = array('#type' => 'hidden', '#value' => $aid, '#prefix' => '<li>', '#suffix' => check_plain($title) ."</li>\n");
   }
   $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
diff --git a/ad.install b/ad.install
index 7f241d6..192df8c 100644
--- a/ad.install
+++ b/ad.install
@@ -307,7 +307,7 @@
  */
 function ad_install() {
   // Create tables.
-  drupal_install_schema('ad');
+  //drupal_install_schema('ad');
 }
 
 /**
@@ -316,7 +316,7 @@
 function ad_uninstall() {
   // Delete all ad content.
   $result = db_query("SELECT nid FROM {node} WHERE type = 'ad'");
-  while ($node = db_fetch_object($result)) {
+  while ($node = $result->fetch()) {
     node_delete($node->nid);
     variable_del("ad_autoactivate_warning_$node->nid");
   }
@@ -329,7 +329,7 @@
   db_query("DELETE FROM {variable} WHERE name LIKE 'ad_block_quantity_%'");
 
   // Remove tables.
-  drupal_uninstall_schema('ad');
+  //drupal_uninstall_schema('ad');
 }
 
 /**
diff --git a/ad.module b/ad.module
index 3243de0..c34ca34 100644
--- a/ad.module
+++ b/ad.module
@@ -246,7 +246,7 @@
     ad_statistics_increment($aid, 'click', $group, $hostid);
   }
   // Determine where we're supposed to redirect the user.
-  $adtype = db_result(db_query('SELECT adtype FROM {ads} WHERE aid = %d', $aid));
+  $adtype = db_query('SELECT adtype FROM {ads} WHERE aid = %d', $aid)->fetchField();
 
   $node->nid = $node->aid = $aid;
   $node->hostid = $hostid;
@@ -411,7 +411,7 @@
         }
         break;
       case 'active':
-        $activated = db_result(db_query("SELECT activated FROM {ads} WHERE aid = %d", $node->nid));
+        $activated = db_query("SELECT activated FROM {ads} WHERE aid = %d", $node->nid)->fetchField();
         if ($activated) {
           $output .= '<p>'. t('This advertisement has been active since %date.', array('%date' => format_date($activated, 'large'))) .'</p>';
         }
@@ -419,16 +419,16 @@
           $output .= '<p>'. t('This advertisement will expire on %timestamp, in %time.', array('%timestamp' => format_date($node->autoexpire, 'large'), '%time' => format_interval($node->autoexpire - time()))) .'</p>';
         }
         if ($node->maxviews) {
-          $views = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $node->nid, date('YmdH', $node->activated)));
+          $views = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $node->nid, date('YmdH', $node->activated))->fetchField();
           $output .= '<p>'. t('This advertisement will expire after %left more impressions.', array('%left' => $node->maxviews - $views)) .'</p>';
         }
         if ($node->maxclicks) {
-          $clicks = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $node->nid, date('YmdH', $node->activated)));
+          $clicks = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $node->nid, date('YmdH', $node->activated))->fetchField();
           $output .= '<p>'. t('This advertisement will expire after %left more clicks.', array('%left' => $node->maxclicks - $clicks)) .'</p>';
         }
         break;
       case 'expired':
-        $expired = db_result(db_query("SELECT expired FROM {ads} WHERE aid = %d", $node->nid));
+        $expired = db_query("SELECT expired FROM {ads} WHERE aid = %d", $node->nid)->fetchField();
         if ($expired) {
           $output .= '<p>'. t('This advertisement expired %date.', array('%date' => format_date($expired, 'large'))) .'</p>';
         }
@@ -474,7 +474,7 @@
   if (time() - variable_get('ad_cron_timestamp', 0) >= 60) {
     // Locate ads that need to be activated or expired.
     $result = db_query('SELECT aid, adstatus, adtype, autoactivate, autoactivated, autoexpire, autoexpired FROM {ads} WHERE autoactivate <> 0 OR autoexpire <> 0');
-    while ($ad = db_fetch_object($result)) {
+    while ($ad = $result->fetch()) {
       switch ($ad->adstatus) {
         case 'approved': {
           // See if this ad is ready to be activated.
@@ -889,7 +889,7 @@
   }
   else if ($form_id == 'search_form' && variable_get('ad_no_search', 1) && !user_access('administer advertisements') && !user_access('administer any advertisement')) {
     $vid = _ad_get_vid();
-    $vocabulary = db_result(db_query('SELECT name FROM {vocabulary} WHERE vid = %d', $vid));
+    $vocabulary = db_query('SELECT name FROM {vocabulary} WHERE vid = %d', $vid)->fetchField();
     unset($form['advanced']['category']['#options'][$vocabulary]);
     if (empty($form['advanced']['category']['#options'])) {
       unset($form['advanced']['category']);
@@ -949,7 +949,7 @@
 
     case 'update':
       if (isset($node->adtype)) {
-        $ad = db_fetch_object(db_query('SELECT * FROM {ads} WHERE aid = %d', $node->nid));
+        $ad = db_query('SELECT * FROM {ads} WHERE aid = %d', $node->nid)->fetch();
         $node->autoactivate = isset($node->autoactivate) ? trim($node->autoactivate) : 0;
         $node->autoactivate = (is_numeric($node->autoactivate)) ? $node->autoactivate : strtotime($node->autoactivate);
         $node->autoexpire = isset($node->autoexpire) ? trim($node->autoexpire) : 0;
@@ -1458,7 +1458,7 @@
   }
 
   // Validate vid in vocabulary table.
-  $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module = 'ad'"));
+  $vid = db_query("SELECT vid FROM {vocabulary} WHERE module = 'ad'")->fetchField();
   if ($vid != variable_get('ad_group_vid', '')) {
     drupal_set_message(t('Invalid vocabulary defined for advertisements, attempting to auto-fix.'), 'error');
     if ($vid) {
@@ -1471,7 +1471,7 @@
     // Validate vid in vocabulary_node_types table.
     $result = db_query("SELECT vid FROM {vocabulary_node_types} WHERE type = 'ad'");
     $found = FALSE;
-    while ($vocab = db_fetch_object($result)) {
+    while ($vocab = $result->fetch()) {
       if ($vocab->vid == variable_get('ad_group_vid', '')) {
         $found = TRUE;
       }
@@ -1494,7 +1494,7 @@
     variable_set('ad_group_vid_restore', '');
   }
 
-  $rid = db_result(db_query_range("SELECT rid FROM {permission} WHERE perm LIKE '%%show advertisements%%'", 1));
+  $rid = db_query_range("SELECT rid FROM {permission} WHERE perm LIKE '%%show advertisements%%'", 1)->fetchField();
   if (!$rid) {
     drupal_set_message(t('Be sure to enable "!show" permissions for all roles that you wish to see advertisements.', array('!show' => l(t('show advertisements'), 'admin/user/permissions'))));
   }
@@ -1541,7 +1541,7 @@
   $vid = variable_get('ad_group_vid', '');
   if (empty($vid)) {
     // No vid stored in the variables table, check if one even exists.
-    $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module = '%s'", 'ad'));
+    $vid = db_query("SELECT vid FROM {vocabulary} WHERE module = '%s'", 'ad')->fetchField();
     if (!$vid) {
       // No vid, so we create one.
       $edit = array(
@@ -1592,7 +1592,7 @@
 
   if (!isset($groups[$nid])) {
     $result = db_query('SELECT d.name FROM {term_data} d LEFT JOIN {term_node} n ON d.tid = n.tid WHERE n.nid = %d AND d.vid = %d', $nid, _ad_get_vid());
-    while ($term = db_fetch_object($result)) {
+    while ($term = $result->fetch()) {
       $terms[] = $term->name;
     }
     if (!empty($terms)) {
diff --git a/ad.pages.inc b/ad.pages.inc
index 281642f..9c71b67 100644
--- a/ad.pages.inc
+++ b/ad.pages.inc
@@ -30,7 +30,7 @@
       $sql .= tablesort_sql($header);
       $result = pager_query($sql, 25, 0, NULL, $node->nid);
 
-      while ($ad = db_fetch_object($result)) {
+      while ($ad = $result->fetch()) {
         if (module_exists('click_filter') && $ad->status != CLICK_VALID) {
           // Only show filtered clicks to users with permission to view them.
           if (!user_access('view filtered clicks')) {
@@ -74,8 +74,8 @@
  */
 function ad_statistics($aid) {
   // Get global statistics.
-  $statistics['global']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view'", $aid));
-  $statistics['global']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click'", $aid));
+  $statistics['global']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view'", $aid)->fetchField();
+  $statistics['global']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click'", $aid)->fetchField();
 
   // No sense in making further queries if the ad has no global statistics.
   if (!$statistics['global']['views'] && !$statistics['global']['clicks']) {
@@ -85,10 +85,10 @@
   // Get statistics for this year and last year.
   $this_year = date('Y000000');
   $last_year = date('Y') - 1 .'000000';
-  $statistics['last_year']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $aid, $last_year, $this_year));
-  $statistics['last_year']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $aid, $last_year, $this_year));
-  $statistics['this_year']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, $this_year));
-  $statistics['this_year']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $aid, $this_year));
+  $statistics['last_year']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $aid, $last_year, $this_year)->fetchField();
+  $statistics['last_year']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $aid, $last_year, $this_year)->fetchField();
+  $statistics['this_year']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, $this_year)->fetchField();
+  $statistics['this_year']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $aid, $this_year)->fetchField();
 
   // No sense in making further queries if the ad has no statistics this year.
   if (!$statistics['this_year']['views'] && !$statistics['this_year']['clicks']) {
@@ -104,10 +104,10 @@
   else {
     $last_month = date('Y') . ($last_month < 10 ? '0' : '') . $last_month .'0000';
   }
-  $statistics['last_month']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $aid, $last_month, $this_month));
-  $statistics['last_month']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $aid, $last_month, $this_month));
-  $statistics['this_month']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, $this_month));
-  $statistics['this_month']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $aid, $this_month));
+  $statistics['last_month']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $aid, $last_month, $this_month)->fetchField();
+  $statistics['last_month']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $aid, $last_month, $this_month)->fetchField();
+  $statistics['this_month']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, $this_month)->fetchField();
+  $statistics['this_month']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $aid, $this_month)->fetchField();
 
   // No sense in making further queries if the ad has no statistics this month.
   if (!$statistics['this_month']['views'] && !$statistics['this_month']['clicks']) {
@@ -116,8 +116,8 @@
 
   // Get statistics for this week.
   $this_week_start = date('Ymd00', time() - 60*60*24*6);
-  $statistics['this_week']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date > %d", $aid, $this_week_start));
-  $statistics['this_week']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date > %d", $aid, $this_week_start));
+  $statistics['this_week']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date > %d", $aid, $this_week_start)->fetchField();
+  $statistics['this_week']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date > %d", $aid, $this_week_start)->fetchField();
 
   // No sense in making further queries if the ad has no statistics this week.
   if (!$statistics['this_week']['views'] && !$statistics['this_week']['clicks']) {
@@ -128,10 +128,10 @@
   $yesterday_start = date('Ymd00', time() - 60*60*24);
   $yesterday_end = date('Ymd24', time() - 60*60*24);
   $today_start = date('Ymd00', time());
-  $statistics['yesterday']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $aid, $yesterday_start, $yesterday_end));
-  $statistics['yesterday']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $aid, $yesterday_start, $yesterday_end));
-  $statistics['today']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, $today_start));
-  $statistics['today']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $aid, $today_start));
+  $statistics['yesterday']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $aid, $yesterday_start, $yesterday_end)->fetchField();
+  $statistics['yesterday']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $aid, $yesterday_start, $yesterday_end)->fetchField();
+  $statistics['today']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, $today_start)->fetchField();
+  $statistics['today']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $aid, $today_start)->fetchField();
 
   // No sense in making further queries if the ad has no statistics today.
   if (!$statistics['today']['views'] && !$statistics['today']['clicks']) {
@@ -141,10 +141,10 @@
   // Get statistics for this hour and the last hour.
   $last_hour = date('YmdH', time() - 60*60);
   $this_hour = date('YmdH', time());
-  $statistics['last_hour']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date = %d", $aid, $last_hour));
-  $statistics['last_hour']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date = %d", $aid, $last_hour));
-  $statistics['this_hour']['views'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date = %d", $aid, $this_hour));
-  $statistics['this_hour']['clicks'] = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date = %d", $aid, $this_hour));
+  $statistics['last_hour']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date = %d", $aid, $last_hour)->fetchField();
+  $statistics['last_hour']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date = %d", $aid, $last_hour)->fetchField();
+  $statistics['this_hour']['views'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date = %d", $aid, $this_hour)->fetchField();
+  $statistics['this_hour']['clicks'] = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date = %d", $aid, $this_hour)->fetchField();
 
   return $statistics;
 }
@@ -191,7 +191,7 @@
  */
 function ad_click_details($node, $cid) {
   drupal_set_breadcrumb(array(l(t('Home'), NULL), l(check_plain($node->title), 'node/'. $node->nid)));
-  if ($click = db_fetch_object(db_query('SELECT * FROM {ad_clicks} WHERE cid = %d', $cid))) {
+  if ($click = db_query('SELECT * FROM {ad_clicks} WHERE cid = %d', $cid)->fetch()) {
     $ad = node_load($click->aid);
     $account = user_load(array('uid' => $click->uid));
     $rows = array(
@@ -261,7 +261,7 @@
       $sql = "SELECT * FROM {ad_statistics} WHERE action NOT IN ('view', 'click') AND aid = %d";
       $sql .= tablesort_sql($header);
       $result = pager_query($sql, 25, 0, NULL, $node->nid);
-      while ($ad = db_fetch_object($result)) {
+      while ($ad = $result->fetch()) {
         $row = array();
         $row[] = format_date(strtotime($ad->date . '00'), 'large');
         $row[] = $ad->action;
diff --git a/ad_token.inc b/ad_token.inc
index 6fe845a..bfe3a5b 100644
--- a/ad_token.inc
+++ b/ad_token.inc
@@ -90,7 +90,7 @@
         if (db_table_exists('ad_owners')) {
           $result = db_query('SELECT a.uid, u.mail, u.name FROM {ad_owners} a INNER JOIN {users} u ON a.uid = u.uid WHERE a.aid = %d', $node->nid);
           $uids = $names = $emails = array();
-          while ($owner = db_fetch_object($result)) {
+          while ($owner = $result->fetch()) {
             $uids[$owner->uid] = $owner->uid;
             $names[$owner->uid] = $owner->name;
             $emails[$owner->uid] = $owner->mail;
diff --git a/adcache.inc b/adcache.inc
index 3701d4f..99fa056 100644
--- a/adcache.inc
+++ b/adcache.inc
@@ -233,7 +233,7 @@
 
   $ids = array();
   if (isset($result)) {
-    while ($ad = db_fetch_object($result)) {
+    while ($ad = $result->fetch()) {
       // perform node access check
       $node = node_load($ad->aid);
       if (node_access('view', $node) !== FALSE) {
@@ -269,7 +269,7 @@
 
   $ad = node_load($id);
   if (!isset($modules[$ad->adtype])) {
-    $modules[$ad->adtype] = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s'", "ad_$ad->adtype"));
+    $modules[$ad->adtype] = db_query("SELECT filename FROM {system} WHERE name = '%s'", "ad_$ad->adtype")->fetchField();
   }
   _debug_echo("Ad type '$ad->adtype', loading module '". $modules[$ad->adtype] ."'");
   return module_invoke("ad_$ad->adtype", 'display_ad', $ad);
@@ -318,10 +318,10 @@
   }
 
   if ($action == 'view') {
-    $ad = db_fetch_object(db_query('SELECT maxviews, activated FROM {ads} WHERE aid = %d', $aid));
+    $ad = db_query('SELECT maxviews, activated FROM {ads} WHERE aid = %d', $aid)->fetch();
     // See if we need to perform additional queries.
     if ($ad->maxviews) {
-      $views = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, date('YmdH', $ad->activated)));
+      $views = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, date('YmdH', $ad->activated))->fetchField();
       if ($views >= $ad->maxviews) {
         db_query("UPDATE {ads} SET adstatus = 'expired', autoexpire = 0, autoexpired = %d, expired = %d WHERE aid = %d", time(), time(), $aid);
         ad_statistics_increment($aid, 'autoexpired');
diff --git a/cache/file/ad_cache_file.module b/cache/file/ad_cache_file.module
index 37c1744..6b17705 100644
--- a/cache/file/ad_cache_file.module
+++ b/cache/file/ad_cache_file.module
@@ -169,10 +169,10 @@
                   }
                   // If counting ad views, see if we've hit a limit
                   if ($action = 'view') {
-                    $limits = db_fetch_object(db_query('SELECT activated, maxviews, maxclicks, adstatus FROM {ads} WHERE aid = %d', $aid));
+                    $limits = db_query('SELECT activated, maxviews, maxclicks, adstatus FROM {ads} WHERE aid = %d', $aid)->fetch();
                     if ($limits->adstatus == 'active') {
                       if ($limits->maxviews) {
-                        $views = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, date('YmdH', $limits->activated)));
+                        $views = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, date('YmdH', $limits->activated))->fetchField();
                         if ($views >= $limits->maxviews) {
                           db_query("UPDATE {ads} SET adstatus = 'expired', autoexpire = 0, autoexpired = %d, expired = %d WHERE aid = %d", time(), time(), $aid);
                           ad_statistics_increment($aid, 'autoexpired');
@@ -180,7 +180,7 @@
                         }
                       }
                       if ($limits->maxclicks) {
-                        $clicks = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $aid, date('YmdH', $limits->activated)));
+                        $clicks = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $aid, date('YmdH', $limits->activated))->fetchField();
                         if ($clicks >= $limits->maxclicks) {
                           db_query("UPDATE {ads} SET adstatus = 'expired', autoexpire = 0, autoexpired = %d, expired = %d WHERE aid = %d", time(), time(), $aid);
                           ad_statistics_increment($aid, 'autoexpired');
@@ -231,7 +231,7 @@
 _debug_echo("SELECT aid FROM ads WHERE adstatus = 'active' OR adstatus = 'approved' OR adstatus = 'offline'");
   $result = db_query("SELECT aid FROM {ads} WHERE adstatus = 'active' OR adstatus = 'approved' OR adstatus = 'offline'");
   $counter = 1;
-  while ($ad = db_fetch_object($result)) {
+  while ($ad = $result->fetch()) {
     _debug_echo("File cache: loading node $ad->aid.");
     $node = node_load($ad->aid);
     _debug_echo("File cache: advertisement $counter: aid($ad->aid) type($node->adtype)");
@@ -247,7 +247,7 @@
     // TODO: Disable this query if ad_remote isn't enabled?
     $owners = db_query('SELECT o.uid, h.hostid FROM {ad_owners} o LEFT JOIN {ad_hosts} h ON o.uid = h.uid WHERE aid = %d', $ad->aid);
     $counter2 = 1;
-    while ($owner = db_fetch_object($owners)) {
+    while ($owner = $owners->fetch()) {
       $cache['uid'][$owner->uid]['aid'][] = $ad->aid;
       $cache['ad'][$ad->aid]['uid'][] = $owner->uid;
       $cache['ad'][$ad->aid][$owner->hostid]['view'] = array();
@@ -259,7 +259,7 @@
     $terms = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $ad->aid);
     $match = FALSE;
     $counter2 = 1;
-    while ($term = db_fetch_object($terms)) {
+    while ($term = $terms->fetch()) {
       $cache['tid'][$term->tid]['aid'][$ad->aid] = $ad->aid;
       $match = TRUE;
       _debug_echo("File cache: term $counter2: tid($term->tid)");
@@ -273,7 +273,7 @@
   // HostID index
   $owners = db_query('SELECT uid, hostid FROM {ad_hosts}');
   $counter = 1;
-  while ($owner = db_fetch_object($owners)) {
+  while ($owner = $owners->fetch()) {
     $cache['uid'][$owner->uid]['hostid'] = $owner->hostid;
     $cache['ad'][0][$owner->hostid]['count'] = array();
     if (($user = user_load(array('uid' => $owner->uid))) &&
diff --git a/channel/ad_channel.install b/channel/ad_channel.install
index e080ec2..f20431e 100644
--- a/channel/ad_channel.install
+++ b/channel/ad_channel.install
@@ -174,7 +174,7 @@
 
 function ad_channel_install() {
   // Create tables
-  drupal_install_schema('ad_channel');
+  //drupal_install_schema('ad_channel');
 }
 
 /**
@@ -182,7 +182,7 @@
  */
 function ad_channel_uninstall() {
   // Drop tables
-  drupal_uninstall_schema('ad_channel');
+  //drupal_uninstall_schema('ad_channel');
 }
 
 /**
@@ -192,7 +192,7 @@
   $ret = array();
 
   $result = db_query('SELECT a.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid');
-  while ($ad = db_fetch_object($result)) {
+  while ($ad = $result->fetch()) {
     if (!isset($ad->priority)) {
       $ret[] = update_sql("INSERT INTO {ad_priority} (aid, priority) VALUES ($ad->aid, 0)");
     }
diff --git a/channel/ad_channel.module b/channel/ad_channel.module
index 4ac274c..a146b8a 100644
--- a/channel/ad_channel.module
+++ b/channel/ad_channel.module
@@ -100,7 +100,7 @@
 function ad_channel_container_load($conid = 0) {
   static $containers = array();
   if (!isset($containers[$conid])) {
-    $containers[$conid] = db_fetch_object(db_query('SELECT * FROM {ad_channel_container} WHERE conid = %d', $conid));
+    $containers[$conid] = db_query('SELECT * FROM {ad_channel_container} WHERE conid = %d', $conid)->fetch();
   }
   return $containers[$conid];
 }
@@ -111,7 +111,7 @@
 function ad_channel_channel_load($chid = 0) {
   static $channels = array();
   if (!isset($channels[$chid])) {
-    $channels[$chid] = db_fetch_object(db_query('SELECT * FROM {ad_channel} WHERE chid = %d', $chid));
+    $channels[$chid] = db_query('SELECT * FROM {ad_channel} WHERE chid = %d', $chid)->fetch();
   }
   return $channels[$chid];
 }
@@ -285,7 +285,7 @@
     foreach ($form['group'] as $aid => $value) {
       $result = db_query('SELECT chid FROM {ad_channel_node} WHERE nid = %d', $aid);
       $names = array();
-      while ($channel = db_fetch_object($result)) {
+      while ($channel = $result->fetch()) {
         $names[] = _ad_channel_get_name($channel->chid);
       }
       if (empty($names)) {
@@ -384,7 +384,7 @@
 function _ad_channel_get_name($chid) {
   static $names = array();
   if (!isset($names[$chid])) {
-    $names[$chid] = db_result(db_query('SELECT name FROM {ad_channel} WHERE chid = %d', $chid));
+    $names[$chid] = db_query('SELECT name FROM {ad_channel} WHERE chid = %d', $chid)->fetchField();
   }
   return $names[$chid];
 }
@@ -566,27 +566,27 @@
   $cache = array();
   $ads = array();
   $active = db_query("SELECT aid FROM {ads} WHERE adstatus = 'active'");
-  while ($ad = db_fetch_object($active)) {
+  while ($ad = $active->fetch()) {
     // cache channel<->node relation
     $result = db_query('SELECT chid FROM {ad_channel_node} WHERE nid = %d', $ad->aid);
-    while ($channel = db_fetch_object($result)) {
+    while ($channel = $result->fetch()) {
       $ads[$ad->aid][$channel->chid] = $channel->chid;
       //$ads[$channel->chid][$ad->aid] = $ad->aid;
     }
   }
   $channels = array();
   $result = db_query('SELECT chid, display, urls, no_channel_percent, inventory FROM {ad_channel}');
-  while ($channel = db_fetch_object($result)) {
+  while ($channel = $result->fetch()) {
     $channels[$channel->chid] = $channel;
   }
   $result = db_query("SELECT p.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid WHERE a.adstatus = 'active' AND p.priority = 1");
   $premiere = array();
-  while ($priority = db_fetch_object($result)) {
+  while ($priority = $result->fetch()) {
     $premiere[$priority->aid] = $priority->aid;
   }
   $result = db_query("SELECT r.aid, r.remnant FROM {ads} a LEFT JOIN {ad_channel_remnant} r ON a.aid = r.aid WHERE a.adstatus = 'active' AND r.remnant = 1");
   $remnants = array();
-  while ($remnant = db_fetch_object($result)) {
+  while ($remnant = $result->fetch()) {
     $remnants[$remnant->aid] = $remnant->aid;
   }
   $cache['channel']['ads'] = $ads;
@@ -684,12 +684,12 @@
 function _ad_channel_load_node($node) {
   $result = db_query('SELECT chid FROM {ad_channel_node} WHERE nid = %d', $node->nid);
   $output['channel'] = array();
-  while ($chid = db_fetch_object($result)) {
+  while ($chid = $result->fetch()) {
     $output['channel'][$chid->chid] = $chid->chid;
   }
   // currently 0 or 1, with one being a 'premiere' advertisement.
-  $output['premiere'] = (int)db_result(db_query('SELECT priority FROM {ad_priority} WHERE aid = %d', $node->nid));
-  $output['remnant'] = (int)db_result(db_query('SELECT remnant FROM {ad_channel_remnant} WHERE aid = %d', $node->nid));
+  $output['premiere'] = (int)db_query('SELECT priority FROM {ad_priority} WHERE aid = %d', $node->nid)->fetchField();
+  $output['remnant'] = (int)db_query('SELECT remnant FROM {ad_channel_remnant} WHERE aid = %d', $node->nid)->fetchField();
   return $output;
 }
 
@@ -854,12 +854,12 @@
   static $cache;
   if (!isset($cache[$conid])) {
     if ($conid) {
-      $cache[$conid] = db_fetch_object(db_query('SELECT * FROM {ad_channel_container} WHERE conid = %d', $conid));
+      $cache[$conid] = db_query('SELECT * FROM {ad_channel_container} WHERE conid = %d', $conid)->fetch();
     }
     else {
       // Get all manually defined channels.
       $result = db_query('SELECT conid, name, description, weight FROM {ad_channel_container} ORDER BY weight ASC');
-      while ($container = db_fetch_object($result)) {
+      while ($container = $result->fetch()) {
         $containers[$container->conid] = $container;
       }
       // Define default 'No container'.
@@ -881,7 +881,7 @@
   if (!isset($cache[$conid])) {
     $channels = array();
     $result = db_query('SELECT chid, name, description, weight, inventory FROM {ad_channel} WHERE conid = %d ORDER BY weight ASC', $conid);
-    while ($channel = db_fetch_object($result)) {
+    while ($channel = $result->fetch()) {
       $channels[$channel->chid] = $channel;
     }
     $cache[$conid] = $channels;
@@ -894,12 +894,12 @@
  */
 function _ad_channel_get_channels($chid = 0) {
   if ($chid) {
-    return db_fetch_object(db_query('SELECT * FROM {ad_channel} WHERE chid = %d', $chid));
+    return db_query('SELECT * FROM {ad_channel} WHERE chid = %d', $chid)->fetch();
   }
   else {
     $channels = array();
     $result = db_query('SELECT chid, name, description FROM {ad_channel}');
-    while ($channel = db_fetch_object($result)) {
+    while ($channel = $result->fetch()) {
       $channels[$channel->chid] = $channel;
     }
     return $channels;
@@ -973,10 +973,10 @@
 function ad_channel_admin_container_validate($form, &$form_state) {
   $conid = 0;
   if ($form_state['values']['op'] == t('Create')) {
-    $conid = db_result(db_query("SELECT conid FROM {ad_channel_container} WHERE name = '%s'", $form_state['values']['name']));
+    $conid = db_query("SELECT conid FROM {ad_channel_container} WHERE name = '%s'", $form_state['values']['name'])->fetchField();
   }
   else if ($form_state['values']['op'] == t('Update')) {
-    $conid = db_result(db_query("SELECT conid FROM {ad_channel_container} WHERE name = '%s' AND conid != %d", $form_state['values']['name'], $form_state['values']['conid']));
+    $conid = db_query("SELECT conid FROM {ad_channel_container} WHERE name = '%s' AND conid != %d", $form_state['values']['name'], $form_state['values']['conid'])->fetchField();
   }
   if ($conid) {
     form_set_error('name', t('A container named %name already exists.', array('%name' => $form_state['values']['name'])));
@@ -1067,7 +1067,7 @@
   );
   $result = db_query('SELECT conid, name FROM {ad_channel_container} ORDER BY weight ASC');
   $containers = array(t('<none>'));
-  while ($container = db_fetch_object($result)) {
+  while ($container = $result->fetch()) {
     $containers[$container->conid] = $container->name;
   }
   if (sizeof($containers) == 1) {
@@ -1208,10 +1208,10 @@
 function ad_channel_admin_channel_validate($form, &$form_state) {
   $chid = 0;
   if ($form_state['values']['op'] == t('Create')) {
-    $chid = db_result(db_query("SELECT chid FROM {ad_channel} WHERE name = '%s'", $form_state['values']['name']));
+    $chid = db_query("SELECT chid FROM {ad_channel} WHERE name = '%s'", $form_state['values']['name'])->fetchField();
   }
   else if ($form_state['values']['op'] == t('Update')) {
-    $chid = db_result(db_query("SELECT chid FROM {ad_channel} WHERE name = '%s' AND chid != %d", $form_state['values']['name'], $form_state['values']['chid']));
+    $chid = db_query("SELECT chid FROM {ad_channel} WHERE name = '%s' AND chid != %d", $form_state['values']['name'], $form_state['values']['chid'])->fetchField();
   }
   if ($chid) {
     form_set_error('name', t('A channel named %name already exists.', array('%name' => $form_state['values']['name'])));
@@ -1318,7 +1318,7 @@
 
 function _ad_channel_get_channel_active_ad_count($chid) {
   if ($chid) {
-    $count = db_result(db_query("SELECT COUNT(nid) AS count FROM {ad_channel_node} acn LEFT JOIN {ads} a ON acn.nid = a.aid WHERE acn.chid = %d AND a.adstatus = 'active'", $chid));
+    $count = db_query("SELECT COUNT(nid) AS count FROM {ad_channel_node} acn LEFT JOIN {ads} a ON acn.nid = a.aid WHERE acn.chid = %d AND a.adstatus = 'active'", $chid)->fetchField();
   }
   return $count;
 }
diff --git a/external/ad_external.install b/external/ad_external.install
index fb03297..ba831e4 100644
--- a/external/ad_external.install
+++ b/external/ad_external.install
@@ -38,12 +38,12 @@
  * ad_external module installation.
  */
 function ad_external_install() {
-  drupal_install_schema('ad_external');
+  //drupal_install_schema('ad_external');
 }
 
 /**
  * Allow complete uninstallation of the ad_external module.
  */
 function ad_external() {
-  drupal_uninstall_schema('ad_external');
+  //drupal_uninstall_schema('ad_external');
 }
diff --git a/external/ad_external.module b/external/ad_external.module
index eb3a42d..57cad10 100644
--- a/external/ad_external.module
+++ b/external/ad_external.module
@@ -41,7 +41,7 @@
       $external = url("$base_url/$adserve?o=external&amp;n=$ad->aid&amp;$display_variables");
     }
     else {
-      $external = db_result(db_query('SELECT url FROM {ad_external} WHERE aid = %d', $ad->aid));
+      $external = db_query('SELECT url FROM {ad_external} WHERE aid = %d', $ad->aid)->fetchField();
     }
     $append = 'frameborder="'. variable_get('ad_iframe_frameborder', 0) .'" ';
     $append .= 'scrolling="'. variable_get('ad_iframe_scroll', 'auto') .'" ';
@@ -190,7 +190,7 @@
 function ad_external_ad_build_cache() {
   $cache = array();
   $result = db_query('SELECT * FROM {ad_external}');
-  while ($external = db_fetch_object($result)) {
+  while ($external = $result->fetch()) {
     $contents = file_get_contents($external->url);
     if ($contents === FALSE) {
       // Failed to download external url, don't cache the error page.
diff --git a/html/ad_html.install b/html/ad_html.install
index d9dc828..f62fa7d 100644
--- a/html/ad_html.install
+++ b/html/ad_html.install
@@ -35,7 +35,7 @@
  * ad_html module installation.
  */
 function ad_html_install() {
-  drupal_install_schema('ad_html');
+ // drupal_install_schema('ad_html');
 }
 
 /**
@@ -44,10 +44,10 @@
 function ad_html_uninstall() {
   // Delete all ad_html content.
   $result = db_query("SELECT aid FROM {ad_html}");
-  while ($aid = db_result($result)) {
+  while ($aid = $result->fetchField()) {
     node_delete($aid);
   }
 
   // Remove tables.
-  drupal_uninstall_schema('ad_html');
+  //drupal_uninstall_schema('ad_html');
 }
diff --git a/image/ad_image.install b/image/ad_image.install
index a9ec118..7da73f3 100644
--- a/image/ad_image.install
+++ b/image/ad_image.install
@@ -112,7 +112,7 @@
  * ad_image module installation.
  */
 function ad_image_install() {
-  drupal_install_schema('ad_image');
+ // drupal_install_schema('ad_image');
 }
 
 /**
@@ -121,12 +121,12 @@
 function ad_image_uninstall() {
   // Delete all ad_image content.
   $result = db_query("SELECT aid FROM {ad_image}");
-  while ($aid = db_result($result)) {
+  while ($aid = $result->fetchField()) {
     node_delete($aid);
   }
 
   // Remove tables.
-  drupal_uninstall_schema('ad_image');
+  //drupal_uninstall_schema('ad_image');
 }
 
 /**
diff --git a/image/ad_image.module b/image/ad_image.module
index 896beb7..4713914 100644
--- a/image/ad_image.module
+++ b/image/ad_image.module
@@ -150,7 +150,7 @@
       '#value' => theme_placeholder("$group->description"),
     );
 
-    $format = db_fetch_object(db_query('SELECT * FROM {ad_image_format} WHERE gid = %d', $tid));
+    $format = db_query('SELECT * FROM {ad_image_format} WHERE gid = %d', $tid)->fetch();
     $form["group-$tid"]["max-size-$tid"] = array(
       '#type' => 'textfield',
       '#title' => t('Maximum filesize'),
@@ -211,7 +211,7 @@
   $groups = module_invoke('ad', 'groups_list', TRUE);
   foreach ($groups as $group) {
     // TODO: Update the database schema, convert gid to tid.
-    $gid = db_result(db_query('SELECT gid FROM {ad_image_format} WHERE gid = %d', $group->tid));
+    $gid = db_query('SELECT gid FROM {ad_image_format} WHERE gid = %d', $group->tid)->fetchField();
     if (is_numeric($gid)) {
       db_query("UPDATE {ad_image_format} SET min_width = %d, max_width = %d, min_height = %d, max_height = %d, max_size = %d WHERE gid = %d", $form_state['values']["min-width-$group->tid"], $form_state['values']["max-width-$group->tid"], $form_state['values']["min-height-$group->tid"], $form_state['values']["max-height-$group->tid"], $form_state['values']["max-size-$group->tid"], $group->tid);
     }
@@ -322,7 +322,7 @@
       return ad_image_node_view($node);
 
     case 'redirect':
-      return db_result(db_query('SELECT url FROM {ad_image} WHERE aid = %d', $node->nid));
+      return db_query('SELECT url FROM {ad_image} WHERE aid = %d', $node->nid)->fetchField();
 
     case 'type':
       return array(
@@ -385,7 +385,7 @@
   if (isset($format[$gid])) {
     return $format[$gid];
   }
-  $format[$gid] = db_fetch_object(db_query('SELECT min_width, max_width, min_height, max_height, max_size FROM {ad_image_format} WHERE gid = %d', $gid));
+  $format[$gid] = db_query('SELECT min_width, max_width, min_height, max_height, max_size FROM {ad_image_format} WHERE gid = %d', $gid)->fetch();
   return $format[$gid];
 }
 
diff --git a/owners/ad_owners.install b/owners/ad_owners.install
index 8c1da2c..1ab761c 100644
--- a/owners/ad_owners.install
+++ b/owners/ad_owners.install
@@ -116,12 +116,12 @@
  * ad_external module installation.
  */
 function ad_owners_install() {
-  drupal_install_schema('ad_owners');
+  //drupal_install_schema('ad_owners');
 }
 
 /**
  * Allow complete uninstallation of the ad_external module.
  */
 function ad_owners() {
-  drupal_uninstall_schema('ad_owners');
+  //drupal_uninstall_schema('ad_owners');
 }
diff --git a/owners/ad_owners.module b/owners/ad_owners.module
index 8afeed0..f4e56dd 100644
--- a/owners/ad_owners.module
+++ b/owners/ad_owners.module
@@ -188,7 +188,7 @@
     case 'delete':
       // Clean up ad_permissions and any other per-ad tables.
       $result = db_query('SELECT oid, uid FROM {ad_owners} WHERE aid = %d', $node->nid);
-      while ($id = db_fetch_object($result)) {
+      while ($id = $result->fetch()) {
         db_query('DELETE FROM {ad_permissions} WHERE oid = %d', $id->oid);
         $owner = user_load(array('uid' => $id->uid));
         // Tell plug-in modules to clean up.
@@ -239,8 +239,8 @@
   }
 
   if (!isset($permissions[$aid][$account->uid])) {
-    $oid = db_result(db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $aid, $account->uid));
-    $permissions[$aid][$account->uid] = explode('|,|', db_result(db_query("SELECT permissions FROM {ad_permissions} WHERE oid = %d", $oid)));
+    $oid = db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $aid, $account->uid)->fetchField();
+    $permissions[$aid][$account->uid] = explode('|,|', db_query("SELECT permissions FROM {ad_permissions} WHERE oid = %d", $oid))->fetchField();
   }
   $access = '';
   if (is_array($permission)) {
@@ -265,7 +265,7 @@
   drupal_set_title(t('Ad owners'));
 
   // Be sure the node owner is listed as an ad owner
-  if (!db_result(db_query('SELECT oid FROM {ad_owners} WHERE uid = %d AND aid = %d', $node->uid, $node->nid))) {
+  if (!db_query('SELECT oid FROM {ad_owners} WHERE uid = %d AND aid = %d', $node->uid, $node->nid)->fetchField()) {
     ad_owners_add($node, $node->uid);
   }
 
@@ -279,7 +279,7 @@
   $result = pager_query($sql, 25, 0, NULL, $node->nid);
 
   $rows = array();
-  while ($owner = db_fetch_object($result)) {
+  while ($owner = $result->fetch()) {
     $row = array();
     $row[] = $owner->name;
     $options = array();
@@ -332,7 +332,7 @@
   if (!is_object($owner)) {
     form_set_error('username', t('The specified username %username does not exist.', array('%username' => $form_state['values']['username'])));
   }
-  else if (db_result(db_query('SELECT oid FROM {ad_owners} WHERE uid = %d AND aid = %d', $owner->uid, $form_state['values']['aid']))) {
+  else if (db_query('SELECT oid FROM {ad_owners} WHERE uid = %d AND aid = %d', $owner->uid, $form_state['values']['aid'])->fetchField()) {
     form_set_error('username', t('The specified user %username is already an owner of this ad.', array('%username' => $form_state['values']['username'])));
   }
   else if (!user_access('edit own advertisements', $owner) &&
@@ -359,7 +359,7 @@
   if (!isset($account)) {
     $account = $user;
   }
-  if (db_result(db_query('SELECT oid FROM {ad_owners} WHERE uid = %d AND aid = %d', $account->uid, $aid))) {
+  if (db_query('SELECT oid FROM {ad_owners} WHERE uid = %d AND aid = %d', $account->uid, $aid)->fetchField()) {
     return 1;
   }
   else {
@@ -373,7 +373,7 @@
 function ad_owners_add($node, $owner, $permissions = array()) {
   $rc = 0;
   $uid = is_numeric($owner) ? $owner : $owner->uid;
-  if (!db_result(db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $node->nid, $uid))) {
+  if (!db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $node->nid, $uid)->fetchField()) {
     db_query('INSERT INTO {ad_owners} (aid, uid) VALUES(%d, %d)', $node->nid, $uid);
     $rc = db_affected_rows() ? 1 : 0;
 
@@ -395,7 +395,7 @@
       }
     }
 
-    $oid = db_result(db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $node->nid, $uid));
+    $oid = db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $node->nid, $uid)->fetchField();
     db_query('DELETE FROM {ad_permissions} WHERE oid = %d', $oid);
     db_query("INSERT INTO {ad_permissions} VALUES(%d, '%s')", $oid, implode('|,|', $permissions));
     module_invoke_all('adowners', 'add', $node, array('oid' => $oid, 'uid' => $uid, 'aid' => $node->nid));
@@ -407,7 +407,7 @@
  * Create a unique host id for each ad owner, used when displaying ads remotely.
  */
 function ad_owners_create_hostid($uid) {
-  $hostid = db_result(db_query('SELECT hostid FROM {ad_hosts} WHERE uid = %d', $uid));
+  $hostid = db_query('SELECT hostid FROM {ad_hosts} WHERE uid = %d', $uid)->fetchField();
   if (!$hostid) {
     $hostid = md5($uid . time());
     db_query("INSERT INTO {ad_hosts} (uid, hostid) VALUES (%d, '%s')", $uid, md5($uid . time()));
@@ -455,7 +455,7 @@
  * Remove the ad owner, and all associated permissions.
  */
 function ad_owner_remove_form_submit($form, &$form_state) {
-  $oid = db_result(db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $form_state['values']['aid'], $form_state['values']['uid']));
+  $oid = db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $form_state['values']['aid'], $form_state['values']['uid'])->fetchField();
   db_query('DELETE FROM {ad_owners} WHERE oid = %d', $oid);
   db_query('DELETE FROM {ad_permissions} WHERE oid = %d', $oid);
   $owner = user_load(array('uid' => $form_state['values']['uid']));
@@ -473,8 +473,8 @@
 function ad_owner_permissions_form($form_state, $node, $user) {
   drupal_set_title(t('Permissions'));
 
-  $oid = db_result(db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $node->nid, $user->uid));
-  $granted = explode('|,|', db_result(db_query("SELECT permissions FROM {ad_permissions} WHERE oid = %d", $oid)));
+  $oid = db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $node->nid, $user->uid)->fetchField();
+  $granted = explode('|,|', db_query("SELECT permissions FROM {ad_permissions} WHERE oid = %d", $oid)->fetchField());
 
   $form['header'] = array(
     '#type' => 'value',
@@ -560,9 +560,9 @@
   static $permissions = array();
 
   if (!isset($permissions[$aid]) || !isset($permissions[$aid][$account->uid])) {
-    $oid = db_result(db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $aid, $account->uid));
+    $oid = db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $aid, $account->uid)->fetchField();
     if ($oid) {
-      $permissions[$aid][$account->uid] = explode('|,|', db_result(db_query("SELECT permissions FROM {ad_permissions} WHERE oid = %d", $oid)));
+      $permissions[$aid][$account->uid] = explode('|,|', db_query("SELECT permissions FROM {ad_permissions} WHERE oid = %d", $oid))->fetchField();
     }
     else {
       $account = user_load($account->uid);
diff --git a/report/ad_report.module b/report/ad_report.module
index 946bec2..f16a3f7 100644
--- a/report/ad_report.module
+++ b/report/ad_report.module
@@ -253,7 +253,7 @@
       $end_date = _ad_report_format_date_db($i + $segment);
       foreach ($ads as $aid) {
         $ad = node_load($aid);
-        $imp = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $aid, $start_date, $end_date));
+        $imp = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $aid, $start_date, $end_date)->fetchField();
         if ($imp > $max) {
           $max = $imp;
         }
@@ -434,7 +434,7 @@
   // Build the query.
   $query = $select .' '. implode(' ', $join) .' WHERE '. implode(' AND ', $where);
   $result = db_query($query, $args);
-  while ($ad = db_fetch_object($result)) {
+  while ($ad = $result->fetch()) {
     if ($ad->nid) {
       $ads[$ad->nid] = $ad->nid;
     }
@@ -456,12 +456,12 @@
   foreach ($ads as $nid) {
     $ad = node_load($nid);
     if ($ad->nid) {
-      $views = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $nid, $start, $end));
-      $first = _ad_report_get_date_from_path((int)db_result(db_query("SELECT MIN(date) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $nid, $start, $end)));
+      $views = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $nid, $start, $end)->fetchField();
+      $first = _ad_report_get_date_from_path((int)db_query("SELECT MIN(date) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $nid, $start, $end)->fetchField());
       $first = format_date($first, 'small');
-      $last = _ad_report_get_date_from_path((int)db_result(db_query("SELECT MAX(date) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $nid, $start, $end)));
+      $last = _ad_report_get_date_from_path((int)db_query("SELECT MAX(date) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $nid, $start, $end)->fetchField());
       $last = format_date($last, 'small');
-      $clicks = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $nid, $start, $end));
+      $clicks = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $nid, $start, $end)->fetchField();
       if ($views) {
         $clickthru = number_format($clicks / $views, 2) .'%';
       }
@@ -721,14 +721,14 @@
       $start_date = _ad_report_format_date_db($i);
       $end_date = _ad_report_format_date_db($i + $segment);
       if ($data['i']) {
-        $imp = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $node->nid, $start_date, $end_date));
+        $imp = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $node->nid, $start_date, $end_date)->fetchField();
         if ($imp > $max) {
           $max = $imp;
         }
         $impressions[] = $imp ? $imp : '0';
       }
       if ($data['c']) {
-        $cli = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $node->nid, $start_date, $end_date));
+        $cli = (int)db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $node->nid, $start_date, $end_date)->fetchField();
         if ($cli > $max) {
           $max = $cli;
         }
diff --git a/statistics/click_filter/click_filter.install b/statistics/click_filter/click_filter.install
index 99d2895..4383236 100644
--- a/statistics/click_filter/click_filter.install
+++ b/statistics/click_filter/click_filter.install
@@ -25,9 +25,9 @@
   $valid = $duplicate = $owner = $bot = 0;
   // Find all unfiltered clicks.
   $result = db_query("SELECT DISTINCT(aid) FROM {ad_clicks} WHERE status = %d", CLICK_NEW);
-  while ($ad = db_fetch_object($result)) {
+  while ($ad = $result->fetch()) {
     $clicks = db_query('SELECT cid, uid, hostname, timestamp, user_agent FROM {ad_clicks} WHERE status = %d AND aid = %d', CLICK_NEW, $ad->aid);
-    while ($click = db_fetch_object($clicks)) {
+    while ($click = $clicks->fetch()) {
       if (preg_match("/bot/i", $click->user_agent)) {
         db_query('UPDATE {ad_clicks} SET status = %d WHERE cid = %d', CLICK_BOT, $click->cid);
         $bot++;
@@ -35,7 +35,7 @@
       }
       // Search for clicks by one of the ad's owners.
       $result = db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $ad->aid, $click->uid);
-      if (db_result($result)) {
+      if ($result->fetchField()) {
         // Mark as clicked by ad owner.
         db_query('UPDATE {ad_clicks} SET status = %d WHERE cid = %d', CLICK_OWNER, $click->cid);
         // Decrement click from ad_statistics table.
@@ -45,7 +45,7 @@
       }
       // Search for duplicate clicks.
       $result = db_query("SELECT cid FROM {ad_clicks} WHERE aid = %d AND status = %d AND cid <> %d AND (uid = %d OR hostname = '%s')", $ad->aid, CLICK_VALID, $click->cid, $click->uid, $click->hostname);
-      if (db_result($result)) {
+      if ($result->fetchField()) {
         // Mark as duplicate click.
         db_query('UPDATE {ad_clicks} SET status = %d WHERE cid = %d', CLICK_DUPLICATE, $click->cid);
         // Decrement click from ad_statistics table.
diff --git a/statistics/click_filter/click_filter.module b/statistics/click_filter/click_filter.module
index b1e6dfb..cf2f3f4 100644
--- a/statistics/click_filter/click_filter.module
+++ b/statistics/click_filter/click_filter.module
@@ -68,7 +68,7 @@
   // See if the click came from an owner of the ad.
   if (module_exists('ad_owners')) {
     $result = db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $aid, $user->uid);
-    if (db_result($result)) {
+    if ($result->fetchField()) {
       return CLICK_OWNER;
     }
   }
@@ -79,7 +79,7 @@
   else {
     $result = db_query("SELECT cid FROM {ad_clicks} WHERE aid = %d AND status = %d AND hostname = '%s'", $aid, CLICK_VALID, ip_address());
   }
-  if (db_result($result)) {
+  if ($result->fetchField()) {
     return CLICK_DUPLICATE;
   }
   return CLICK_VALID;
diff --git a/text/ad_text.install b/text/ad_text.install
index 286ae6e..6d57b98 100644
--- a/text/ad_text.install
+++ b/text/ad_text.install
@@ -48,7 +48,7 @@
  * ad_text module installation.
  */
 function ad_text_install() {
-  drupal_install_schema('ad_text');
+  //drupal_install_schema('ad_text');
 }
 
 /**
@@ -57,10 +57,10 @@
 function ad_text_uninstall() {
   // Delete all ad_text content.
   $result = db_query("SELECT aid FROM {ad_text}");
-  while ($aid = db_result($result)) {
+  while ($aid = $result->fetchField()) {
     node_delete($aid);
   }
 
   // Remove tables.
-  drupal_uninstall_schema('ad_text');
+  //drupal_uninstall_schema('ad_text');
 }
diff --git a/text/ad_text.module b/text/ad_text.module
index 9381da1..1daad0f 100644
--- a/text/ad_text.module
+++ b/text/ad_text.module
@@ -217,7 +217,7 @@
       return ad_text_node_view($node);
 
     case 'redirect':
-      return db_result(db_query('SELECT url FROM {ad_text} WHERE aid = %d', $node->nid));
+      return db_query('SELECT url FROM {ad_text} WHERE aid = %d', $node->nid)->fetchField();
 
     case 'validate':
       $todo = array();
diff --git a/weight/percent/ad_weight_percent.module b/weight/percent/ad_weight_percent.module
index ea647aa..4a66743 100644
--- a/weight/percent/ad_weight_percent.module
+++ b/weight/percent/ad_weight_percent.module
@@ -76,9 +76,9 @@
     );
 
     $result = db_query('SELECT nid FROM {term_node} WHERE tid = %d', $group->tid);
-    while ($nid = db_fetch_object($result)) {
+    while ($nid = $result->fetch()) {
       $ad = node_load($nid->nid);
-      $percent = db_fetch_object(db_query('SELECT * FROM {ad_weight_percent} WHERE tid = %d AND aid = %d', $tid, $nid->nid));
+      $percent = db_query('SELECT * FROM {ad_weight_percent} WHERE tid = %d AND aid = %d', $tid, $nid->nid)->fetch();
       $form["group-$tid"]["ad-$tid"]["$tid-$nid->nid"] = array(
         '#type' => 'fieldset',
         '#title' => $ad->title,
@@ -121,7 +121,7 @@
       $total = 0;
       // Add up total percentages for all nids in group, confirm equals 100%.
       $first = 0;
-      while ($nid = db_fetch_object($result)) {
+      while ($nid = $result->fetch()) {
         if (!$first) $first = $nid->nid;
         $total = $total + (int)$form_state['values']["percent-$tid-$nid->nid"];
       }
@@ -142,7 +142,7 @@
     variable_set("enable-$tid", (int)$form_state['values']["enable-$tid"]);
     db_query('DELETE FROM {ad_weight_percent} WHERE tid = %d', $tid);
     $result = db_query('SELECT nid FROM {term_node} WHERE tid = %d', $group->tid);
-    while ($nid = db_fetch_object($result)) {
+    while ($nid = $result->fetch()) {
       db_query('INSERT INTO {ad_weight_percent} (tid, aid, weight) VALUES(%d, %d, %d)', $tid, $nid->nid, (int)$form_state['values']["percent-$tid-$nid->nid"]);
     }
   }
diff --git a/weight/probability/ad_weight_probability.module b/weight/probability/ad_weight_probability.module
index 9281c64..b789cab 100644
--- a/weight/probability/ad_weight_probability.module
+++ b/weight/probability/ad_weight_probability.module
@@ -87,7 +87,7 @@
 function ad_weight_probability_ad_build_cache() {
   $cache = array();
   $active = db_query("SELECT a.aid, p.probability FROM {ads} a LEFT JOIN {ad_weight_probability} p ON a.aid = p.aid WHERE adstatus = 'active'");
-  while ($ad = db_fetch_object($active)) {
+  while ($ad = $active->fetch()) {
     $probability = $ad->probability ? $ad->probability : AD_PROBABILITY_DEFAULT;
     $ads[$ad->aid] = $probability;
   }
@@ -104,7 +104,7 @@
  * Helper function, load the probability from the database.
  */
 function _ad_weight_probability_node_load($node) {
-  $probability = (int)db_result(db_query('SELECT probability FROM {ad_weight_probability} WHERE aid = %d', $node->nid));
+  $probability = (int)db_query('SELECT probability FROM {ad_weight_probability} WHERE aid = %d', $node->nid)->fetchField();
   $output['probability'] = $probability ? $probability : AD_PROBABILITY_DEFAULT;
   return $output;
 }
