2

How would I go about extracting the data from a DB into fields? I would like to display information on a page using Views, but the information isn't on the website, instead it is in a separate database. Is this possible?

I get that in order to use Views I need to have fields, but how do I extract this?

4 Answers 4

1

If you just want the content, you can use Feeds as Patrick said but this will replicate the content of the other database as entities in your Drupal site.

If you really want views connecting to a remote database, this question looks like a duplicate of:

https://drupal.stackexchange.com/questions/3275/how-do-i-display-an-external-database-data

This will help you make Drupal "aware" of the external db:

http://drupal.org/node/18429

5
  • Sorry, may I just ask if you would recommend the same procedure if for example the data I want to extract IS in the drupal database, just a different table. For example it was imported into the database via a csv file so it already is in the database. But obviously in my drupal instance there are no fields because the data was directly moved to the database. If that makes sense...
    – user12804
    Commented Jan 20, 2013 at 0:36
  • Why not just use hook_views_data to make views aware of your tables then write a views handler to display it how you want? api.drupal.org/api/views/views.api.php/function/hook_views_data/… Commented Jan 20, 2013 at 5:36
  • Thank you. Will read up on that. I'm very new to drupal and even newer to views :)
    – user12804
    Commented Jan 20, 2013 at 7:21
  • Is hook_views_data difficult to use for a drupal beginner? Do I need to know php at all?
    – user12804
    Commented Jan 20, 2013 at 7:24
  • Yes, you need to know quite a bit of PHP. Writing the hook requires moderate knowledge of Drupal and PHP but writing the handler requires an understanding of Object Oriented Programming. TBH, I don't know how well you're going to go directly accessing external databases with limited PHP knowledge... I'd recommend the Feeds approach if you're a beginner. Commented Jan 20, 2013 at 12:42
0

If you can get the data from the database in CSV or OPML format, you can use the Feeds module. It's quite complex to set up, but it does have decent documentation.

1
  • Thank you. What about a custom search which should search the content of this database (not the homepage). Should that be added as a separate block and then linked to the db via the feeds module as well?
    – user12804
    Commented Jan 19, 2013 at 8:43
0

Consider the Forena module (disclosure: I'm a co-maintainer of it), here is a summary of it:

Forena is built of the idea of using SQL to get data out of a database and use XHTML and CSS to format it into web reports.

Various DBMSs are supported, such as Oracle, MS Sql, Postgress, SQLite, MySQL, any PDO compliant DBMS ... And there are quite some reasons for considering Forena.

Refer to the example in my answer to How to retrieve data directly from a Drupal database to get an idea about using Forena, i.e.:

  • establish a DB connection.
  • a custom SQL query.
  • a custom report.

Forena can also be used for importing data (from an external database ...) into a Drupal site, using its integration with the feeds module. Or you can use its integration with the views module to create views about data retrieved from such external database.

Refer to the available community documentation for (way) more details, and/or the sample reports and graphs in the demo site (which processes data stored in an SQLite database, one of the supported DBMSes).

-1

The data module would help you to achieve what you are looking for.

Here is a quote about it (from the module's project page):

... helps you model, manage and query related sets of tables. It offers an administration interface and a low level API for manipulating tables and accessing their contents. Data module provides Views integration for displaying table data and Drupal search integration for searching table content.

2
  • Thank you. What about a custom search which should search the content of this database (not the homepage). Should that be added as a separate block and then linked to the db via the data module as well?
    – user12804
    Commented Jan 19, 2013 at 8:44
  • if the views integration works with your db using the module then you should be able to use the exposed filters to create a search functionality Commented Jan 19, 2013 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.