Fix small mistype
[squirrelmail.git] / doc / db-backend.txt
CommitLineData
6ff1c690 1$Id$
2
3
4Storing private addressbooks and preferences in a database
5==========================================================
6
7
8On sites with many users you might want to store your user data in a
1e63b430 9database instead of in files. This document describes how to configure
6ff1c690 10SquirrelMail to do this.
11
12Methods for storing both personal addressbooks and user preferences in
1e63b430 13a database is included as a part of the distribution.
6ff1c690 14
15
16
17Configuring PEAR DB
18-------------------
19
20To work you must install the PEAR classes that is a part of PHP. Make
21sure the directory where the PEAR files are located is a part of your
22include path. See the PHP documentation for info on how to do that.
23
24
25
26Configuring addressbooks in database
27------------------------------------
28
29First you need to create a database and a table to store the data in.
30Create a database user with access to read and write in that table.
31
32For MySQL you would normally do something like:
33
34 (from the command line)
35 # mysqladmin create squirrelmail
36
37 (from the mysql client)
38 mysql> GRANT select,insert,update,delete ON squirrelmail.*
39 TO squrreluser@localhost IDENTIFIED BY 'sqpassword';
40
41The table structure should be similar to this (for MySQL):
42
43 CREATE TABLE address (
1e63b430 44 owner varchar(128) DEFAULT '' NOT NULL,
6ff1c690 45 nickname varchar(16) DEFAULT '' NOT NULL,
46 firstname varchar(128) DEFAULT '' NOT NULL,
47 lastname varchar(128) DEFAULT '' NOT NULL,
48 email varchar(128) DEFAULT '' NOT NULL,
49 label varchar(255),
50 PRIMARY KEY (owner,nickname),
51 KEY firstname (firstname,lastname)
52 );
53
54
4f40a59d 55Next, edit your configuration so that the address book DSN (Data Source
56Name) is specified, this can be done using either conf.pl or via the
57administration plugin. The DSN should look something like:
6ff1c690 58
59 $addrbook_dsn = 'mysql://squirreluser:sqpassword@localhost/squirrelmail';
60
61From now on all users' personal addressbooks will be stored in a
62database.
63
64
65
66Configuring preferences in database
67-----------------------------------
68
69There is no easy way to do this yet. You will have to remove
70functions/prefs.php and replace it with functions/db_prefs.php. Then
71edit the new functions/prefs.php (db_prefs.php) and change the $DSN to
72point to a database you create (can be the same you use for
73addressbooks). Create a table similar to this (for MySQL):
74
75 CREATE TABLE userprefs (
1e63b430 76 user varchar(128) DEFAULT '' NOT NULL,
6ff1c690 77 prefkey varchar(64) DEFAULT '' NOT NULL,
1e63b430 78 prefval BLOB DEFAULT '' NOT NULL,
6ff1c690 79 PRIMARY KEY (user,prefkey)
80 );
81
82
83Default preferences can be set by altering the $default array in
84prefs.php (db_prefs.php).
85