Connect Drupal and Views to External Databases

Drupal Views Database Connector

We often get asked whether Drupal can show information from other websites.

In particular, people want to pull information and display it through Views.

The Views Database Connector module makes this relatively easy. Let’s show you how it’s done.

First, install Views Database Connector from Drupal.org.

Second, go to your sites/default/settings.php file. You will need to edit this file to include the connection information for the new database. The settings.php file already contains information for your current Drupal site. You need to add a second array to include the new database login details. Here’s how the code will look:

Views Database Connector and settings.php
  • Clear the cache on your site to make sure the new settings.php file is being used.
  • Go to Structure > Views > Add new view.
  • Under the “Show” dropdown, you’ll now see all the available tables from your other database:
Views Database Connector and the Views module

From this point on, you can use Views to show external data, in exactly the same way as you show Drupal data.

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Article Rating
Subscribe
Notify of
31 Comments
Oldest
Newest
Inline Feedbacks
View all comments
SimonW
8 years ago

interesting …

pepperstreet
8 years ago

So simple, so powerful. Thanks for the headsup!

steve
steve
8 years ago
Reply to  pepperstreet

Thanks, pepperstreet. I was surprised how well it worked, given that not many people are using it.

Harshal
Harshal
8 years ago

I am trying to use the above module for Drupal 8 with patch [url=https://www.drupal.org/files/issues/drupal8rc_patch.txt]https://www.drupal.org/file…[/url] as given but it does not work, would like you to update the above for D8

Irene Moghis
Irene Moghis
7 years ago

Not so easy. I did the db connection but can’t see the views from the content drop down.

vimal fresh
vimal fresh
7 years ago

Thanks usefull

Gil Carroll
Gil Carroll
7 years ago

I think this does not work for Oracle databases. Can you confirm? Connecting mysql is easy-peasy but Oracle is so far unsuccessful.

steve
steve
7 years ago
Reply to  Gil Carroll

Sorry, we don’t have an Oracle db to test this with

Angelo
Angelo
7 years ago

i tried with the last version 8.26, i edited the settings.php i put the databases in the same you show us in the example and doesnt show nothinng new in the show dropdown.

Please i need Help!

Thanks in advanced!

daniel-pickering
7 years ago
Reply to  Angelo

Hi Angelo,
This is a Drupal 7 tutorial. Drupal 8 is very different.
Thanks

Daniel

Angelo
Angelo
7 years ago

thanks for the answer, Daniel!

daniel-pickering
7 years ago
Reply to  Angelo

Hi Angelo,
We can have a look at getting it to work and doing an updated tutorial if that would be useful to you.
Thanks,

Daniel

Angelo
Angelo
7 years ago

Yes, Please!

and i will send you the gift card!

this is my email angelogiuseppepezzotti@gmail.com

Angelo
Angelo
7 years ago

HI Daniel,

i want to show contents from my external database in a view but i don’t know how to do it in drupal 8.26 version? could you please give me a hand?

i know is not to much but i could offer you a 10 euros gift card.

Please!

Blessings!

daniel-pickering
7 years ago
Reply to  Angelo

Hi Angelo,
What enviroment are you developing your Drupal 8 site with?

Angelo
Angelo
7 years ago

Linux

daniel-pickering
7 years ago
Reply to  Angelo

Have a read of this it should help you figure out the difference.

[url=https://www.drupal.org/node/2710557]https://www.drupal.org/node…[/url]
Thanks

Daniel

Angelo
Angelo
7 years ago

Thanks!, but i still dont’understand how to apply that!

steve
steve
7 years ago
Reply to  Angelo

Angelo, if you need a lot of help, please consider becoming an OSTraining member. That’s really where we can give the best support, not in the comments.

Angelo
Angelo
7 years ago

MySQL

Kido
Kido
6 years ago

Hi, i have to connect to 5 databases. I managed to display 3 of them, but 2 are not displayed. Settings are the same, and when I change order of databases it still displays first three in a list. I use xampp, and I’m not sure if there are any limitations?

djilymbow01
djilymbow01
6 years ago

Hello
In fact I use drupal 8 with the view database connector but I did the connection of my second database. Here is my configuration
$ databases [‘default’] [‘default’] = array (
   ‘database’ => ‘bd_drupal8’,
   ‘username’ => ‘root’,
   ‘password’ => ”,
   ‘prefix’ => ”,
   ‘host’ => ‘localhost’,
   ‘port’ => ‘3306’,
   ‘namespace’ => ‘Drupal \\ Core \\ Database \\ Driver \\ mysql’,
   ‘driver’ => ‘mysql’,
);
$ databases [‘external’] [‘default’] = array (
   ‘database’ => ‘student’,
   ‘username’ => ‘root’,
   ‘password’ => ”,
   ‘prefix’ => ‘etu_’,
   ‘host’ => ‘localhost’,
   ‘port’ => ‘3306’,
   ‘namespace’ => ‘Drupal \\ Core \\ Database \\ Driver \\ mysql’,
   ‘driver’ => ‘mysql’,
);
But my problem is that I can see my tables from my second database ‘ma_base’ when I want to create a view. Thank you for pointing out the problem if there is either to help me to make a good configuration.

Ric
Ric
5 years ago

Hi,
As per tutorial I have added the second database and successfully able to see the list of tables in drop down. But the issue is in the drop down only a few tables are available. Can you please help me out.
PS: I am using Drupal 7

Kevin
Kevin
4 years ago

Be aware that views_database_connector does not allow you to create joins between tables.

nilesh7521
3 years ago

Hi Steve I have one Q. I am using Drupal 8 and  have successfully installed View Database Connector Module.  Suppose I have external database that holds each and every information of employee of the company and needs 50 columns for that. Out of that 50 columns I am able to display  Name, Image, Contact, Email, Room No from particular department of the company by selecting department using filter in VIEWS.  So far so good.

Now I want to pull all data from external database  if i click on Name or Image of the employee like we link  Image or Title  to parent content in Drupal. How to go about it ? Thanking you, Nilesh.

nilesh7521
3 years ago
Reply to  steve

Hi Steve,
thank you for your reply and clarification. May I ask you one more question?  How to display an image stored in the external database in [b]BLOB[/b] format. Right now I have stored URL of an image in the external database. I pull it using “Views Database Connector” module. Then I use rewrite rule to display it as follows.
[code]sometext[/code]
Thanking you once again.

nilesh7521
3 years ago
Reply to  steve

Hi Steve
is it possible to join two tables in an external database and create a view out of them using “Views Database Connector” Module ? Thank you for extending your help.

nilesh7521
3 years ago
Reply to  steve

Dear Steve
thanks for your reply. It is still  a great module to display contents form external DB without writing a single piece of code. I appreciate your willingness to help. Thanking you once again.

CHRISTIAN WADÉN
CHRISTIAN WADÉN
3 years ago

SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘wellingt_drup4.droc_droc_wellington_horserace’ doesn’t exist:

I see droc_ 2 times…

31
0
Would love your thoughts, please comment.x
()
x