Drupal Database API Basics - Drupal Training Curriculum for Drupal Companies

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

Back to Drupal Training Syllabus

Drupal Database API Basics

The course covers the basics of database functions.

Learning Objective

Trainee will be able to do all the basic database transactions, like select, insert, update and delete.

Course Content

  1. Introduction

  2. Database API provides a standard, vendor-agnostic abstraction layer for accessing database servers.
    https://www.drupal.org/developing/api/database

  3. Create DB

  4. In Drupal 7 and earlier versions before running the installation script, developer must create an empty database and database user.
    Since 8.x, it is not necessary to create a database before installing Drupal. Now, the specified database name will be created at the time of Drupal installation if it doesn't already exist.
    https://www.drupal.org/documentation/install/create-database

  5. Select, Insert, Update, Delete

  6. Drupal's database abstraction layer provides a unified database query API that can query different underlying databases. It is built upon PHP's PDO (PHP Data Objects) database API, and inherits much of its syntax and semantics. Besides providing a unified API for database queries, the database abstraction layer also provides a structured way to construct complex queries, and it protects the database by using good security practices.
    https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!database.api.php/group/database/8

  7. Database Abstraction Layer

  8. Drupal provides a database abstraction layer to provide developers with the ability to support multiple database servers easily. The intent of this layer is to preserve the syntax and power of SQL as much as possible, but also allow developers a way to leverage more complex functionality in a unified way. It also provides a structured interface for dynamically constructing queries when appropriate, and enforcing security checks and similar good practices.
    http://praxent.com/blog/introduction-to-drupals-database-abstraction-lay...

  9. Query optimization

  10. In order to increase the performance of Drupal website, it is important to optimize the query.
    https://drupalwatchdog.com/volume-4/issue-1/mysql-query-optimization

Reference

https://buildamodule.com/video/drupal-7-development-core-concepts-how-to...
https://www.drupal.org/node/811594

Exercise

Exercise on Database API

Next » Drupal Security Guidelines