Table updates and installation

When SPIP installs itself, it uses particular functions to install or update its tables. Plugins may also use these functions in their own installation routines.

These functions are declared in the ecrire/base/create.php file.

Creating tables

The creer_base($connect='') function creates tables missing in the database which has the connection file specified in $connect. By default, this is the principal connection.

This function creates the missing tables (of course, they must have already been defined), but does nothing for modifying an existing table. If the table is declared as a principal table (and not an auxiliary table), and if the primary key is an integer, then SPIP will automatically assign an ’auto-increment’ type to this primary key.

Updating tables

The maj_tables($tables, $connect='') function updates existing tables. It will only create fields that are missing; no field deletion will be performed. The table name (character string) or list of table names (table) must be provided to the function. There again, it is possible to specify a different connection file other than the principal database.

If a table to be updated does not exist, it will be created, following the same principle as creer_base() does for the auto-increment.

Examples:

  1. include_spip('base/create');
  2. creer_base();
  3. maj_tables('spip_rubriques');
  4. maj_tables(array('spip_rubriques','spip_articles'));

Download

Author Mark Baber Published : Updated : 12/05/17

Translations : English, français