Hi! I'm newbie here. I have installed Drupal 5.1 and mySQL 6.0. I created a database for drupal and want to display the information into my drupal website. The problem is I do not know where to start. How to call out the records from the database and display it on the drupal website? Drupal is totally new to me. Please help... Thanks in advance!

Comments

schwa’s picture

hi there,

Drupal functions as a tool that both creates and then calls content via a web browser interface, from a database that has been specifically configured during your Drupal installation. It doesn't work to pull content from any external prepopulated mySQl database that you may have created separately (for that, you could use plain php pages, you wouldn't need Drupal).

How far have you gotten in the installation? When you created the mySQL database, did you then go to the Drupal install page to set up the various tables in it? What happens when you go to the URL of your root Drupal installation (which is possibly something like www.mysite.com/drupal ) ? Do you see a front page, or connection errors?

yhat’s picture

Hi schwa, after my installation, it prompted me to enter the database name and password. Then I created the database using command prompt and entered those info into it. After that I managed to create first user login and able to customize and configure my website freely. From here, I can add menu, page and story but I do not know how to link drupal with my existing database which contains records to be displayed on my website. This is where I'm stuck with. Please advise...

adam_b’s picture

This isn't a simple job - migrating content between databases is complex even if they're both MySQL, as the database structure will be completely different. You could look at the Node Import module (http://drupal.org/project/node_import) but I suspect that you'll need professional help.

schwa’s picture

Yes, that's a very difficult and delicate task. Depending on the amount of information and your ultimate goal with the Drupal site, you might consider biting the bullet and re-entering the data into Drupal, using custom content types to match the necessary fields. Or find a professional database expert to help you achieve the migration.

If you can code, there are ways to pull in discrete bits of data from alternate databases by writing custom php ( http://drupal.org/node/18429 ), for instance creating a page that makes the call and lists the content of your alternate db. But then you'd lose the advantage of any interactivity with that content which is probably the main reason to use a cms in the first place.

best of luck, sorry your first task is such a hard one, and welcome to Drupal!

Markjdz’s picture

Hi,
I've just started with Drupal also and was trying to connect to a second database and found this post at
http://drupal.org/node/18429

First off, you have to edit your settings.php file, which is in /sites/default. You might have to use chmod to change the permissions on it because I think Drupal locks it after installation. Around line 90, there is a line like this:
$db_url = 'mysql://username:password@localhost/drupaldb';

You have to change that to make $db_url an array and add a second line for the second database, so you will end up with something like this (replacing user1,pwd1,user2,pwd2 with what is appropriate for your set up; also, the keys don't have to be dafault or legacy, they can be whatever you want:

$db_url['default'] = 'mysql://user1:pwd1@localhost/drupaldb';
$db_url['legacy'] = 'mysql://user2:pwd2@localhost/otherdb';

When you want to access the second database, you use a statement like
db_set_active('legacy');
You can then read from your old database, but you have to switch back to the Drupal database with db_set_active('default'); before you do anything that would use Drupal.

To do a test of this, I created a block that read from the user table in the mysql system database and displayed the host and user name. Here is the code I put in the block body:

print "Here is markdb test<br/>";
db_set_active('legacy');
$results = db_query("SELECT * FROM {user} ");
while ( $data = db_fetch_object($results)) {
     $host = $data->Host;
     $user = $data->User;
     print "host $host - user is $user<br/>";
}
db_set_active('default');

I also changed the Input Type to PHP Code, instead of Filtered HTML

The first time I did this I had misconfigured a database setting and got a database access error that locked me out of Drupal. To get back in, I used the command line to go into the Drupal database and disabled all of my blocks with this:
UPDATE BLOCKS SET STATUS="0" WHERE MODULE="block";

I hope this helps.
Mark