The Data module is 1 of 2 modules in Drupal that attempt to let you manage and use database tables not created by Drupal. The other module is called Table Wizard (which appears abandoned now). By itself the Data module allows you to create SQL tables in Drupal using a basic admin UI (a baby version of phpmyadmin for example). It also lets you adopt previously defined sql tables in your database, which are not created or maintained by drupal initially.
After installing the Data module (and it’s dependency the Ctools module). You’ll then be able to create simple SQL tables that support an API to be interacted with from custom modules you can create.
Then you can easily create a new table by selecting the Create New Table option. This will walk you through a small wizard to make you’re new table. The other option is called Adopt Table which I’ll describe later. For example we can create a simple table Foo1 with some simple columns:
Out of the box the Data module supports the following fields: Integer, Serial, VarChar, Text, Float and Geometry (geometry my be an add-on field from other modules installed on my drupal site in this case).
Upon creating the table the Data module admin page then lists our custom table(s) with available actions on the table:
The actions include:
- Edit: Modify the table structure.
- Disown: Have Data unregister the table from its management system (making the underlying API faster). But retain the data and table in the underlying DBMS.
- Drop: Drop the table from the DBMS and Drupal.
- Export: Export the table structure to code.
- View Records: View the data in the table.
- Edit View: Manage the Views page through the Views Admin UI for this custom table.
So thus far on the backend of our system Data has created a simple SQL table:
And ultimately we’ve created a View to display foo1 on our website:
Earlier I mentioned the Adopt Table option. This lets you adopt a non-drupal table from your Database and make it usable through the Data API and viewable by Views. For simplicity I will use phpMyAdmin to copy a table from a different project into my drupal database. Then Data can see it to be adopted:
In order to View Records for our new table we must first goto the Edit View page and define the Views handler mappings for the fields within the table:
Basically, I would accept the default values this form presents you. And then try to goto the View Records page and if it’s blank or gives you an error — then go back to Edit View and attempt to pick different field handlers than the defaults provided.
Then our data is visible in Drupal:
This is most of the functionality of the Data module. Also look at what it can do with Feeds and Entities from the project page; but those topics are more advanced and I will not cover them at this time.
Looking for quality web hosting? Look no further than Arvixe Web Hosting!