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
Blog Rating
Subscribe
Notify of
31 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
SimonW

interesting …

pepperstreet

So simple, so powerful. Thanks for the headsup!

steve

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

Harshal

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

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

vimal fresh

Thanks usefull

Gil Carroll

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

steve

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

Angelo

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

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

Daniel

Angelo

thanks for the answer, Daniel!

daniel-pickering

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

Yes, Please!

and i will send you the gift card!

this is my email angelogiuseppepezzotti@gmail.com

Angelo

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

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

Angelo

Linux

daniel-pickering

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

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

steve

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

MySQL

Kido

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

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

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

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

nilesh7521

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

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

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

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

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