Declaring another database

In order to access another database, SPIP needs to have access codes to that database. At the time of writing, secondary declared databases are correctly handled in read mode. Writing to such databases, however, is not yet handled by SPIP 2.

To declare another database, there are two possible solutions:

  • use the standard graphical interface defined for that purpose (Configuration > Site maintenance > Declare another database)
  • write your own connector file following the syntax defined for that purpose, and store it in the config/ directory (or the directory defined by the constant _DIR_CONNECT).

The connector file config/xx.php

For a connector file called tarabiscote.php, its content would be:

if (!defined("_ECRIRE_INC_VERSION")) return;
$GLOBALS['spip_connect_version'] = 0.7;
spip_connect_db('localhost','','username','password','tarabiscote','mysql', 'spip','');

We would then call the spip_connect_db() function using the following arguments in that order:

  1. the address of the sql server
  2. the connecting port number, if necessary
  3. the username
  4. the password
  5. the database name
  6. the server type (mysql, pg, sqlite2, sqlite3...)
  7. the table prefix
  8. are users connected using ldap ?

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français, Nederlands