All globals removed. hmmmm .... fasten seat belts ....
[squirrelmail.git] / doc / db-backend.txt
... / ...
CommitLineData
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
9database instead of in files. This document describes how to configure
10SquirrelMail to do this.
11
12Methods for storing both personal addressbooks and user preferences in
13a database is included as a part of the distribution.
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 (
44 owner varchar(128) DEFAULT '' NOT NULL,
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
55Next, edit config/config.php and add a DSN (Data Source Name) for the
56database. It should look something like:
57
58 $addrbook_dsn = 'mysql://squirreluser:sqpassword@localhost/squirrelmail';
59
60From now on all users' personal addressbooks will be stored in a
61database.
62
63
64
65Configuring preferences in database
66-----------------------------------
67
68There is no easy way to do this yet. You will have to remove
69functions/prefs.php and replace it with functions/db_prefs.php. Then
70edit the new functions/prefs.php (db_prefs.php) and change the $DSN to
71point to a database you create (can be the same you use for
72addressbooks). Create a table similar to this (for MySQL):
73
74 CREATE TABLE userprefs (
75 user varchar(128) DEFAULT '' NOT NULL,
76 prefkey varchar(64) DEFAULT '' NOT NULL,
77 prefval BLOB DEFAULT '' NOT NULL,
78 PRIMARY KEY (user,prefkey)
79 );
80
81
82Default preferences can be set by altering the $default array in
83prefs.php (db_prefs.php).
84