[support] Can't change database connection

Earnie Boyd earnie at users.sourceforge.net
Wed Jan 2 03:28:25 UTC 2013


The schema doesn't come from the database but from the modules that
implement a schema.  The schema will exist regardless of which
connection you're connected to.
http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_get_schema/7

Earnie

On Tue, Jan 1, 2013 at 9:37 PM, Tim Johnson <tim at akwebsoft.com> wrote:
> 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
> --
> Tim
> tim at tee jay forty nine dot com or akwebsoft dot com
> http://www.akwebsoft.com
> --
> [ Drupal support list | http://lists.drupal.org/ ]



-- 
Earnie
-- https://sites.google.com/site/earnieboyd


More information about the support mailing list