Posts

Showing posts from February 15, 2013

connect to multiple database from drupal

Drupal has the ability to connect to multiple databases, allowing you to use Drupal’s built in database abstraction layer on more than just Drupal's primary database. Preferably you would add your configuration in the settings.php file for your site, so that all modules can interact with the new database. Drupal 7 In your settings.php: $databases = array(); $databases['default']['default'] = array( // Drupal's default credentials here. // This is where the Drupal core will store it's data. ); $databases['alternate_db']['default'] = array( // Your secondary database's credentials here. // You will be able to explicitly connect to this database from your modules. ); The way to use it in module: // Use the database we set up earlier db_set_active('alternate_db'); // Run some queries, process some data db_query('...............'); //Switch back to the default connection when finished. // other