I'm attempting to switch my database connection on drupal 7. Based on http://drupal.org/node/18429 I have written the following module code : // code : $dba = array ( 'driver' => 'mysql', 'database' => 'dolphy_books', 'host' => 'localhost', 'username' => 'tim', 'password' => '******', ); // Test the current connnection $result = Database::getConnectionInfo('default'); drupal_set_message("<b>Connection Info</b>: <pre>" . print_r($result,1) . '</pre>'); // Verify that table 'actions' exists $result = drupal_get_schema('actions'); drupal_set_message("<b>schema</b>: <pre>" . print_r($result,1) . '</pre>'); // change the connection to the one defined by $dba Database::addConnectionInfo('db1','default',$dba); db_set_active('db1'); // Test what should now be the current connection. And the info for // $dba is returned $result = Database::getConnectionInfo('db1'); drupal_set_message("<b>Now : Connection Info</b>: <pre>" . print_r($result,1) . '</pre>'); // There is no 'actions' table in the 'dolphy_books' database. The // following code should generate and error $result = drupal_get_schema('actions'); drupal_set_message("<b>schema</b>: <pre>" . print_r($result,1) . '</pre>'); // YIKES! We are still seeing the 'actions' table. DB switch failed. // end code
The diagnostics that I have put in indicate (to the best that I can see) that the appropriate connection info has been provided. **BUT** the connection has not been changed! The second call to `drupal_get_schema' returns the same schema info as before the calls to addConnectionInfo and db_set_active. In fact, there is no table named 'actions' in the 'dolphy_books' database.
I could really use some help here. This has got me tearing my hair out and believe me, I've got little to spare!
thanks