The easiest and most correct way to create and maintain Moodle data tables is through the database plugin mechanism. You will have noticed (as we used this in the previous chapters) that almost all plugins have an optional db
subdirectory that contain files which manage data tables specific to the plugin. It is this subdirectory and the files within it that allow you to easily manage your data tables.
The db
subdirectory can typically contains four files: install.xml, upgrade.php, access.php
, and events.php
. The first two are the ones we are concerned with here.
The install.xml
file contains XML that defines the tables required for your new plugin. It is a generic (database-agnostic) way to define data tables such that they can be created in just about any database technology (MySQL, PostgreSQL, and so on).
The following is a sample from the label
module:
<?xml version="1.0" encoding="UTF-8" ?> <XMLDB PATH="mod/label/db" VERSION="20060905...