diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 1e4eaba..9eb0c64 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,23 +1,2 @@
-Webform MySQL Views 6.x-1.2, 2011-01-14
-* Fix for [#1026208] - grid component values are now formatted as a
-  comma-separated list of key=val expressions.
-* Fixed [#1026522] - When building the view query, field names are enclosed
-  with backticks to avoid collisions with MySQL reserved words.
-* [#1024200] Applied excellent patch from Frega, which adds automatic
-  integration with the Data and Views modulse and thereby makes Webform MySQL
-  views available
-  to the Drupal Views module.
-* Fix for [#1027092]: View name deduping logic uses active database name.
-  Also includes a fix for $db_prefix handling in general.
-* Fix for [#1024192] - $db_prefix is now properly prepended to the view name
-  before storing it in the webform_mysql_views_views system variable.
-
-Webform MySQL Views 6.x-1.1, 2011-01-11
-* Fixed #1005606 - Omit fieldset components
-* Fixed #1005600 - View breaks if a field allows multiple values
-* Updated README.txt to address #1006648, confusion about 
-  MySQL Views vs Drupal Views
-* Added CHANGELOG.txt
-
-Webform MySQL Views 6.x-1.0, 2010-12-22
-* Initial Release
\ No newline at end of file
+Webform MySQL Views 7.x-1.0, 2011-05-18
+* Initial Release
diff --git a/README.txt b/README.txt
index d946e89..37b036e 100644
--- a/README.txt
+++ b/README.txt
@@ -1,3 +1,4 @@
+/* $Id: README.txt,v 1.1.2.2 2011/01/14 19:37:45 usonian Exp $ */
 
 -- SUMMARY --
 
diff --git a/webform_mysql_views.info b/webform_mysql_views.info
index 1d4bea6..305743e 100644
--- a/webform_mysql_views.info
+++ b/webform_mysql_views.info
@@ -2,6 +2,6 @@
 name = Webform MySQL Views
 description = Create flattened MySQL views from Webform submission data
 package = Webform
-core = 6.x
+core = 7.x
 dependencies[] = webform
 dependencies[] = elements
\ No newline at end of file
diff --git a/webform_mysql_views.install b/webform_mysql_views.install
index 73ad938..23df4ec 100644
--- a/webform_mysql_views.install
+++ b/webform_mysql_views.install
@@ -1,4 +1,4 @@
-<?php // $Id$
+<?php // $Id: webform_mysql_views.install,v 1.1 2010/12/22 17:29:18 usonian Exp $
 
 /**
  * @file
diff --git a/webform_mysql_views.module b/webform_mysql_views.module
index fa2bb89..550027d 100644
--- a/webform_mysql_views.module
+++ b/webform_mysql_views.module
@@ -1,4 +1,4 @@
-<?php // $Id$
+<?php
 
 /**
  * @file
@@ -7,6 +7,7 @@
  * applications.
  *
  * @author Andy Chase <andychase@gmail.com>
+ * @author Joe Corall <joe.corall@gmail.com>
  */
 
 /**
@@ -95,7 +96,8 @@ function webform_mysql_views_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  */
 function webform_mysql_views_rebuild($nid, $add_new = FALSE) {
 
-  global $db_prefix;
+  global $databases;
+  $db_prefix = $databases['default']['default']['prefix'];
 
   $views = variable_get('webform_mysql_views_views', array());
   $name = NULL;
@@ -108,7 +110,7 @@ function webform_mysql_views_rebuild($nid, $add_new = FALSE) {
     variable_set('webform_mysql_views_views', $views);
   }
 
-  if ($views[$nid]) {
+  if (in_array($nid,$views)) {
     // Remove the $db_prefix from the view name so we don't wind up with double
     // db_prefixes:
     if ($db_prefix) {
@@ -118,6 +120,7 @@ function webform_mysql_views_rebuild($nid, $add_new = FALSE) {
       $name = $views[$nid];
     }
     $query = webform_mysql_views_build_query($nid, $name);
+
     db_query($query);
   }
 
@@ -136,7 +139,7 @@ function webform_mysql_views_rebuild($nid, $add_new = FALSE) {
 function webform_mysql_views_drop($nid) {
   $views = variable_get('webform_mysql_views_views', array());
   if (!empty($views[$nid])) {
-    db_query("DROP VIEW {%s}", $views[$nid]);
+    db_query("DROP VIEW {". $views[$nid] . "}");
     unset($views[$nid]);
     variable_set('webform_mysql_views_views', $views);
   }
@@ -170,34 +173,29 @@ function webform_mysql_views_help($path) {
  */
 function webform_mysql_views_admin_form() {
 
-
   $meets_reqs = _webform_mysql_views_check_requirements();
-  if ($meets_reqs !== TRUE) {
+  if (!$meets_reqs) {
     $output = '<strong>'. t("This module will not work on this site.") .'</strong>';
     $output .= theme('item_list', $meets_reqs, t('Details'));
-
     return array("error" => array('#value' => $output));
   }
 
-
   // Get list of webform-enabled content types
-  $types = webform_variable_get('webform_node_types', array());
+  $types = webform_variable_get('webform_node_types');
 
   //Get list of nids that already have views
   $views = variable_get('webform_mysql_views_views', array());
   $view_nids = array_keys($views);
 
   //Get list of all webform nodes
-  $query = db_rewrite_sql("SELECT nid, title FROM {node} n WHERE type IN ('%s') AND status = 1 ORDER BY nid");
-  $result = db_query($query, implode("','", $types));
-
-
+  $query = "SELECT nid, title FROM {node} n WHERE type IN('" . implode("','",$types) . "') AND status = 1 ORDER BY nid";
+  $result = db_query($query);
   $options = array();
   $titles = array();
   $default_value = array();
-  while ($node = db_fetch_object($result)) {
+  foreach ($result as $node) {
     $titles[$node->nid] = $node->title;
-    if (in_array($node->nid, $view_nids)) {
+    if (array_key_exists($node->nid, $view_nids)) {
       $default_value[$node->nid] = $node->nid;
     }
     if (in_array($node->nid, $view_nids)) {
@@ -211,7 +209,6 @@ function webform_mysql_views_admin_form() {
   }
 
   $form = array();
-
   //Pass the titles along
   $form['titles'] = array(
     '#type' => 'value',
@@ -236,6 +233,7 @@ function webform_mysql_views_admin_form() {
     '#type' => 'submit',
     '#value' => t('Submit'),
   );
+
   return $form;
 
 }
@@ -246,8 +244,8 @@ function webform_mysql_views_admin_form() {
  * @see webform_mysql_views_admin_form()
  */
 function webform_mysql_views_admin_form_submit($form, &$form_state) {
-
-  global $db_prefix;
+  global $databases;
+  $db_prefix = $databases['default']['default']['prefix'];
 
   //Load existing view info
   $webform_views = $previous_webform_views = variable_get('webform_mysql_views_views', array());
@@ -264,9 +262,9 @@ function webform_mysql_views_admin_form_submit($form, &$form_state) {
   //If there are any nids in the saved array not in the newly submitted one, drop those views.
   $drop_nids = array_diff($webform_view_nids, $submitted_nids);
   foreach ($drop_nids as $nid) {
-    $query = "DROP VIEW {%s}";
+    $query = "DROP VIEW {" . substr($webform_views[$nid], strlen($db_prefix)) . "}" ;
     // (Drop the prefix from the stored view name and let the DB API handle it)
-    db_query($query, substr($webform_views[$nid], strlen($db_prefix)));
+    db_query($query);
     unset($webform_views[$nid]);
   }
   if (count($drop_nids)) {
@@ -343,28 +341,36 @@ function webform_mysql_views_build_query($nid, $view_name) {
   // the MySQL server group_concat_max_length setting is usually limited to
   // 1024 characters, and it's easier to work around that here than tinkering
   // with the my.cnf file.
+  $query = "SELECT c.cid, c.form_key, c.type FROM {webform_component} c WHERE c.nid = "
+           . $nid
+           . " AND c.type != 'fieldset' ORDER BY c.weight ASC, c.cid ASC";
 
-  $result = db_query('SELECT c.cid, c.form_key, c.type FROM {webform_component} c WHERE c.nid = %d AND c.type != "fieldset" ORDER BY c.weight ASC, c.cid ASC', $nid);
+  $result = db_query($query);
   $components = '';
+  $str = '';
+  foreach ($result as $row) {
+     $str .=  "\n NEW \n";
+     $str .= $row->type;
 
-  while ($row = db_fetch_array($result)) {
-    switch ($row['type']) {
+    switch ($row->type) {
       //Collapse grid values in a string of key=val pairs
       case 'grid':
-        $component = sprintf("(SELECT GROUP_CONCAT(no,'=',data) FROM {webform_submitted_data} AS child WHERE child.sid = parent.sid AND cid = %d) AS `%s`, ", $row['cid'], $row['form_key']);
+        $component = sprintf("(SELECT GROUP_CONCAT(no,'=',data) FROM {webform_submitted_data} AS child WHERE child.sid = parent.sid AND cid = %d) AS `%s`, ", $row->cid, $row->form_key);
         break;
       //Otherwise collapse multi-value fields into simple comma-separated lists
       default:
-        $component = sprintf("(SELECT GROUP_CONCAT(data) FROM {webform_submitted_data} AS child WHERE child.sid = parent.sid AND cid = %d) AS `%s`, ", $row['cid'], $row['form_key']);
+        $component = sprintf("(SELECT GROUP_CONCAT(data) FROM {webform_submitted_data} AS child WHERE child.sid = parent.sid AND cid = %d) AS `%s`, ", $row->cid, $row->form_key);
     }
     $components .= $component;
   }
-
-  $query = "CREATE OR REPLACE VIEW {%s} AS SELECT parent.sid, s.uid,"
+  $f = fopen('/var/www/cph/t.txt','w'); fwrite($f,$str); fclose($f);
+  $query = "CREATE OR REPLACE VIEW {".$view_name."} AS SELECT parent.sid, s.uid,"
            . $components
-           .' FROM_UNIXTIME(s.submitted) AS submitted, s.remote_addr FROM {webform_submitted_data} AS parent JOIN {webform_submissions} s ON s.sid = parent.sid WHERE parent.nid = %d GROUP BY parent.sid ORDER BY parent.sid DESC;';
+           ." s.submitted AS submitted, s.remote_addr FROM {webform_submitted_data} AS parent JOIN {webform_submissions} s ON s.sid = parent.sid WHERE parent.nid = "
+           . $nid
+           ." GROUP BY parent.sid ORDER BY parent.sid DESC";
 
-  return sprintf($query, $view_name, $nid);
+  return $query;
 }
 
 /**
@@ -378,21 +384,28 @@ function webform_mysql_views_build_query($nid, $view_name) {
  */
 function webform_mysql_views_get_view_name($title, $nid) {
 
-  global $db_url, $db_prefix;
+  global $databases;
+  $db_url = $databases['default']['default']['driver'];
+  $db_prefix = $databases['default']['default']['prefix'];
 
   //Discard non-alphanumeric chars
   $title = strtolower(str_replace(' ', '_', $title));
   $title = 'webform_views_'. preg_replace('/[^a-z0-9_]/', '', $title);
 
   $db_name = substr(parse_url($db_url, PHP_URL_PATH), 1);
-
   // Check whether the default view name is already being used
   // (For example duplicate node titles). Append $nid if necessary to ensure
   // uniqueness.  Table names not escaped as they are not a part of the Drupal DB.
+  $query = "SELECT COUNT(table_name) AS view_exists FROM information_schema.views where table_schema = '"
+           . $db_name
+           . "' AND table_name = '"
+           . $db_prefix
+           . $title
+           ."'";
 
-  $view_exists = db_result(db_query("SELECT COUNT(table_name) AS view_exists FROM information_schema.views where table_schema = '%s' AND table_name = '%s%s'", $db_name, $db_prefix, $title));
+  $view_exists = db_query($query);
 
-  if ($view_exists) {
+  if (isset($view_exists)) {
     return $title .'_'. $nid;
   }
 
@@ -404,8 +417,6 @@ function webform_mysql_views_get_view_name($title, $nid) {
  */
 function _webform_mysql_views_check_requirements() {
 
-  global $db_url;
-
   $meets_reqs = variable_set('webform_mysql_views_meets_reqs', FALSE);
 
   if ($meets_reqs) {
@@ -413,15 +424,19 @@ function _webform_mysql_views_check_requirements() {
   }
   else {
     $errors = array();
+
     //Make sure site is using MySQL backend
-    if (substr($db_url, 0, 5) != 'mysql') {
+    global $databases;
+    $db_url = $databases['default']['default']['driver'];
+    if (strcmp($db_url,'mysql')) {
       $errors[] = t("This module is only compatible with the MySQL backend.");
     }
 
-    //Make sure server major version is 5
-    $version = db_result(db_query("SELECT version() AS version"));
-    if ((int)substr($version, 0, 1) < 5) {
-      $errors[] = t("This module requires MySQL server version 5.0 or later.  Your server is running version @version.", array('@version' => $version));
+    //Make sure site is using MySQL version 5.0 or higher
+    $result = db_query("SELECT version() AS version")->fetchField();
+    $version = (int)substr($result,0,1);
+    if ($version < 5) {
+      $errors[] = t('This module is only compatible with MySQL 5.0 or newer');
     }
 
     if (count($errors) == 0) {
