Connect Drupal and Views to External Databases

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:

- 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:

From this point on, you can use Views to show external data, in exactly the same way as you show Drupal data.
interesting …
So simple, so powerful. Thanks for the headsup!
Thanks, pepperstreet. I was surprised how well it worked, given that not many people are using it.
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
Not so easy. I did the db connection but can’t see the views from the content drop down.
Thanks usefull
I think this does not work for Oracle databases. Can you confirm? Connecting mysql is easy-peasy but Oracle is so far unsuccessful.
Sorry, we don’t have an Oracle db to test this with
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!
Hi Angelo,
This is a Drupal 7 tutorial. Drupal 8 is very different.
Thanks
Daniel
thanks for the answer, Daniel!
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
Yes, Please!
and i will send you the gift card!
this is my email angelogiuseppepezzotti@gmail.com
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!
Hi Angelo,
What enviroment are you developing your Drupal 8 site with?
Linux
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
Thanks!, but i still dont’understand how to apply that!
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.
MySQL
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?
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.
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
Be aware that views_database_connector does not allow you to create joins between tables.
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.
Hi Nilesh. Unfortunately, you’ll probably need a some custom code to go further with this. As far as I know, “Views Database Connector” is limited to pulling data from your original data source.
Hi Steve,
[/code]
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]
Thanking you once again.
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.
Hi Nilesh. Again, sorry, I think this module is too basic for that. Although it has been 5 years since I wrote this – my memory is a little foggy.
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.
SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘wellingt_drup4.droc_droc_wellington_horserace’ doesn’t exist:
I see droc_ 2 times…