diff --git a/engines/mysql.inc b/engines/mysql.inc
index f86aaa3..4335544 100644
--- a/engines/mysql.inc
+++ b/engines/mysql.inc
@@ -30,8 +30,8 @@ class SchemaDatabaseSchema_mysql extends DatabaseSchema_mysql {
 
   public function inspect($connection = 'default', $name = NULL) {
     // Get the current database name
-    $info = Database::getConnectionInfo($connection);
-    $database = $info['default']['database'];
+    $info = $this->connection->getConnectionOptions();
+    $database = $info['database'];
 
     $tables = array();
     $args = array(':database' => $database);
@@ -42,7 +42,7 @@ class SchemaDatabaseSchema_mysql extends DatabaseSchema_mysql {
       $sql .= 'AND table_name = :table ';
       $args[':table'] = $name;
     }
-    $res = db_query($sql, $args);
+    $res = $this->connection->query($sql, $args);
     foreach ($res as $r) {
       $tables[$r->table_name]['description'] = $r->table_comment;
     }
@@ -56,7 +56,7 @@ class SchemaDatabaseSchema_mysql extends DatabaseSchema_mysql {
     }
     $sql .= 'ORDER BY table_name, ordinal_position';
 
-    $res = db_query($sql, $args);
+    $res = $this->connection->query($sql, $args);
     foreach ($res as $r) {
       $r->new_table_name = schema_unprefix_table($r->table_name);
 
@@ -107,7 +107,7 @@ class SchemaDatabaseSchema_mysql extends DatabaseSchema_mysql {
     }
     $sql .= 'ORDER BY table_name, index_name, seq_in_index';
 
-    $res = db_query($sql, $args);
+    $res = $this->connection->query($sql, $args);
     foreach ($res as $r) {
       if (isset($r->sub_part) && !is_null($r->sub_part)) {
         $col = array($r->column_name, intval($r->sub_part));
diff --git a/engines/pgsql.inc b/engines/pgsql.inc
index 6accfa0..d054305 100644
--- a/engines/pgsql.inc
+++ b/engines/pgsql.inc
@@ -32,13 +32,13 @@ class SchemaDatabaseSchema_pgsql extends DatabaseSchema_pgsql {
 
   public function inspect($connection = 'default', $tbl_name = NULL) {
     // Get the current database name
-    $info = Database::getConnectionInfo($connection);
-    $database = $info['default']['database'];
+    $info = $this->connection->getConnectionOptions();
+    $database = $info['database'];
 
     //
     // Retrieve information about all columns in the database from the
     // 'columns' table of 'information_schema'.  In pgsql, TABLE_CATALOG
-    // is the database name and we provide $database to db_query below.
+    // is the database name and we provide $database to query() below.
     // We sort the columns by table_name and ordinal_position so the get
     // added to our array in the same order.
     //
@@ -51,7 +51,7 @@ class SchemaDatabaseSchema_pgsql extends DatabaseSchema_pgsql {
     }
     $sql .= 'ORDER BY table_name, ordinal_position';
 
-    $res = db_query($sql, $tokens);
+    $res = $this->connection->query($sql, $tokens);
 
     //
     // Add an entry to $tables[<tablename>]['fields'] for each column.  $r
@@ -156,7 +156,7 @@ class SchemaDatabaseSchema_pgsql extends DatabaseSchema_pgsql {
     // Make sur we caught all the unsigned columns.  I could not get
     // this to work as a left join on the previous query.
     //
-    $res = db_query('SELECT ccu.*, cc.check_clause
+    $res = $this->connection->query('SELECT ccu.*, cc.check_clause
                      FROM information_schema.constraint_column_usage ccu
                      INNER JOIN information_schema.check_constraints cc ON ccu.constraint_name=cc.constraint_name
                      WHERE table_schema=current_schema()');
@@ -176,7 +176,7 @@ class SchemaDatabaseSchema_pgsql extends DatabaseSchema_pgsql {
     // the CREATE INDEX statement to create the index; we parse it to
     // produce our data structure.  Ick.
     //
-    $res = db_query('SELECT n.nspname, c.relname AS tblname, ' .
+    $res = $this->connection->query('SELECT n.nspname, c.relname AS tblname, ' .
       '   c2.relname AS indname, i.indisprimary, i.indisunique, ' .
       '   pg_get_indexdef(i.indexrelid) AS inddef ' .
       'FROM pg_class c, pg_class c2, pg_index i, pg_namespace n ' .
diff --git a/schema.module b/schema.module
index d1bf7ce..484de04 100755
--- a/schema.module
+++ b/schema.module
@@ -173,13 +173,40 @@ function schema_unprefix_table($name) {
   return $name;
 }
 
-function schema_dbobject() {
-  static $engines = array();
-  $class_name = 'SchemaDatabaseSchema_' . db_driver();
-  if (!isset($engines[$class_name])) {
-    $engines[$class_name] = new $class_name(Database::getConnection());
+/**
+ * Fetch the schema engine class name for a given database connection.
+ *
+ * @param string $connection
+ *   A database connection key, defaults to 'default'.
+ *
+ * @return
+ *   The schema engine class name if available, otherwise FALSE.
+ */
+function schema_get_connection_engine_class($connection = 'default') {
+  if ($info = Database::getConnectionInfo($connection)) {
+    $driver = $info['default']['driver'];
+    $class_name = 'SchemaDatabaseSchema_' . $driver;
+    if (class_exists($class_name)) {
+      return $class_name;
+    }
+  }
+
+  return FALSE;
+}
+
+/**
+ * Fetch a schema engine class instance for a given database connection.
+ *
+ * @param string $connection
+ *   A database connection key, defaults to 'default'.
+ *
+ * @return object
+ *   A schema engine class set to the given connection.
+ */
+function schema_dbobject($connection = 'default') {
+  if ($class = schema_get_connection_engine_class($connection)) {
+    return new $class(Database::getConnection('default', $connection));
   }
-  return $engines[$class_name];
 }
 
 /**
@@ -225,7 +252,7 @@ function schema_schema_type($type, $table, $field, $engine = NULL) {
  */
 function schema_compare_schemas($ref, $inspect = NULL) {
   if (!isset($inspect)) {
-    $inspect = schema_dbobject()->inspect(variable_get('schema_database_connection', 'default'));
+    $inspect = schema_dbobject(variable_get('schema_database_connection', 'default'))->inspect();
   }
 
   $info = array();
@@ -327,8 +354,7 @@ function schema_compare_table($ref, $inspect = NULL) {
     // TODO: Handle prefixing the D7 way
 //    $ref_name = db_prefix_tables('{' . $ref['name'] . '}');
     $ref_name = $ref['name'];
-    $inspect = schema_dbobject()->inspect(
-      variable_get('schema_database_connection', 'default'), $ref_name);
+    $inspect = schema_dbobject(variable_get('schema_database_connection', 'default'))->inspect(NULL, $ref_name);
     $inspect = $inspect[$ref['name']];
   }
   if (!isset($inspect)) {
@@ -796,7 +822,7 @@ function schema_inspect() {
   sort($mods);
   $mods = array_flip($mods);
   $schema = drupal_get_schema(NULL, TRUE);
-  $inspect = schema_dbobject()->inspect(variable_get('schema_database_connection', 'default'));
+  $inspect = schema_dbobject(variable_get('schema_database_connection', 'default'))->inspect();
   foreach ($inspect as $name => $table) {
     $module = isset($schema[$name]['module']) ? $schema[$name]['module'] : 'Unknown';
     if (!isset($form[$module])) {
