Hi!

I want to add list of Prague universities on my drupal page somvprahe.sk

For this case, I created new database with tables 'universities' & 'study_sections'

But now, I don't know how to connect Drupal to this new database.

I suppose that then I will create new page, I set format to php,
and then I include script for connect to new database, fetch data and close.

I found that drupal has API for connect to the database and work with it.
so I could to use db_connect for connect to my new database?
but where I can set param $url for db_connect($url),
is it in sites/default/settings.php, where are access informations for drupal database too?

so in this file I could add new rows
e.g.
$url['user'] = login
$url['pass'] = pass
$url['host'] = host
$url['path'] = path
or maybe no? :)

and the last questions, there is no function as db_close() in drupal db api. If I usedb_connect($url), at will be close the connection at the end of the process or no?

I work with drupal for 1 year, but till now I don't try to access to another database so I am newbie with this.
Thanks for your help.

Comments

Horla’s picture

add the other database to sites/default/settings.php

$db_url['default'] = 'mysql://xxx:xxx@localhost/drupal';
$db_url['new_database'] = 'mysql://xxx:xxx@localhost/new_database';

and connect to the database with

db_set_active('new_database');

and close it always with

db_set_active('default');