Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Adding a table to the database

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:07
    In this chapter I'm going to show you
  • 0:09
    how to create a database table for your module to use.
  • 0:13
    In our previous chapter, we created a module that counted
  • 0:18
    how many times you had viewed a page.
  • 0:20
    We're going to take that example one step further
  • 0:23
    and rather than saving something in the sessions or in a variable,
  • 0:27
    we're actually going to save it in our own module's table.
  • 0:31
    So let's take a look at the code that we originally were working with.
  • 0:34
    I have a module here, named Demo 2,
  • 0:36
    my .info file is a basic file and my .module file

Adding a Table to the Database


In this chapter we learn how to create a new database table. This example walks through creating a module that defines the the properties of our new table and also programatically creating that table. We learn about hook_schema() and hook_update_N() in our module's install file.

Trainers note: This video starts out with a module that implements hook_node_view() and stores data about views in the $_SESSION variable. It also states that we built this earlier in the series. However, that's not true. We did talk about hook_node_view() in, but we never actually wrote the $_SESSION handling part. So, if you're following along and want the same sample code we start with make sure you download the code attached to this node.

Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.