Multiple concurrent database connections in drupal 7

To configure a concurrent database where you are not required to do context switching use the following code snippet.

$target='default';
$key = 'db2';
$db2 = Database::getConnection($target,$key);
$result = $phpbb->query($sql,$args,$opts);

This assumes you have a database configured in your settings.php like the following:

$databases['db2']['default'] = array(
    'driver' => 'mysql',
    'database' => 'forum',
    'username' => 'username',
    'password' => 'password',
    'host' => 'mysql.host.com',
    'prefix' => 'db2_'
);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s