18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1<br />

The database<br />

We have taken a brisk walk through a typical <strong>Drupal</strong> request, and we have learned a<br />

little about modules and libraries. However, what about the database?<br />

Unlike many architectures, for <strong>Drupal</strong> the database doesn't stand front and center.<br />

The database layer is not a module, nor do modules need to declare a specific<br />

relationship with the database. In fact, many <strong>Drupal</strong> modules do not ever interact<br />

directly with the database.<br />

Unlike Model-View-Controller (MVC) frameworks, <strong>Drupal</strong><br />

does not require that modules follow an MVC pattern. For<br />

that reason, a module can exist, yet not have any database<br />

structures (models), a central controller, or even any usercentered<br />

theming (view).<br />

Instead of treating the database as a central architectural component, <strong>Drupal</strong> merely<br />

provides an API for working with the database. In <strong>Drupal</strong>, the database is just a<br />

place to store data. Need custom tables? <strong>Drupal</strong> provides a system for declaring<br />

them. Need to get data out of the database, or insert or update new data? <strong>Drupal</strong><br />

provides functions and an OO library for doing so. However, if you don't need such<br />

features for your code, you needn't work with the database at all. In fact, in the next<br />

chapter we will write our first module without writing a single SQL query.<br />

Later in this book, we will see how to interact with the database using <strong>Drupal</strong>'s<br />

robust database tools.<br />

More than just data<br />

The <strong>Drupal</strong> database does not store just application data (or<br />

content), but also configuration, caches, metadata (data about<br />

data), structural information, and sometimes even PHP code.<br />

While <strong>Drupal</strong> may not be database centric, it most certainly requires a database.<br />

During initialization, <strong>Drupal</strong> will connect to a database and retrieve certain<br />

configuration data. Later, as many of the core modules load, they too, contact the<br />

database to retrieve or update information. For most <strong>Drupal</strong> modules, the database<br />

is the location for data storage.<br />

[ 15 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!