[drupal-devel] external database queries?

Matt Westgate matt at asitis.org
Sat Mar 5 16:09:44 UTC 2005

On Saturday 05 March 2005 09:09 am, Sheldon Rampton wrote:
> I'd like to write some code that will let my Drupal installation do
> some queries of my MediaWiki database, which is a separate MySQL
> database than my Drupal database. And, I'd like to be able to take
> advantage of some of the nice tools that Drupal provides for managing
> query results, such as the pager. Can anyone suggest how I might do
> this?

Drupal handles this with amazing ease!

Specify the db connection settings in your settings.php or conf.php file as an 
associative array.

  $db_url['default'] = 'mysql://drupal:drupal@localhost/drupal';
  $db_url['wiki'] = 'mysql://user:pwd@localhost/mywiki';

When you want to connect to the external database:


db_query('SELECT * FROM other_db');

//Switch back to the default connection


More information about the drupal-devel mailing list