[drupal-devel] external database queries?
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? --Sheldon Rampton
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_set_active('mywiki'); db_query('SELECT * FROM other_db'); //Switch back to the default connection db_set_active('default'); Docs: http://drupaldocs.org/api/head/function/db_set_active http://cvs.drupal.org/viewcvs/drupal/drupal/sites/default/settings.php?view=...
Hi, Op zaterdag 5 maart 2005 16:09, schreef Sheldon Rampton:
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? Since I am no DB guru no. But I suggest you start with reading about modules and such in the Drupal Handbook.
And also, Eventhough this might sound like a development issue, it really is a support question. WE have exellent support channels and systems for everyone, so please use those, so that others too can benefit from the answers you get. Regards, Bèr -- [ Bèr Kessels | Drupal services www.webschuur.com ]
On Saturday 05 March 2005 10:19 am, Bèr Kessels wrote:
Hi,
Op zaterdag 5 maart 2005 16:09, schreef Sheldon Rampton:
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?
Since I am no DB guru no. But I suggest you start with reading about modules and such in the Drupal Handbook.
And also, Eventhough this might sound like a development issue, it really is a support question. WE have exellent support channels and systems for everyone, so please use those, so that others too can benefit from the answers you get.
Good point Bèr. I created a page regarding multiple database connections in the handbook. http://drupal.org/node/18429 Matt
participants (3)
-
Bèr Kessels -
Matt Westgate -
Sheldon Rampton