Drupal 6: Creating database schema for a Drupal module and inserting database records
Here’s a quick guide on how to create database schema for your module. The first thing you should do is get acquainted with the Schema API documentation.
You’ll need to create a file in your module directory called: MYMODULE.install. In this file, you’ll define hook_schema, hook_install, hook_uninstall, etc. Here’s an example that defines 3 columns, the primary key, and a unique key.
A full list of data types can be found here.
This documentation explains the structure of the schema array.
Now you can define how to install and uninstall the schema:
More information on schema functions can be found here.
In your module code to write a database record you simply define an array/object containing your columns and the data you’d like to insert, and then use the function drupal_write_record:
More information on writing to the database can be found here.