adding notice about configtest hook
[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
4dccdc01 20For this to work you must have the PEAR classes installed, these are
21part of PHP. Once these are installed you must have sure the directory
22containg them is a part of your PHP include path. See the PHP
23documentation for information on how to do that.
24Under Mandrake Linux the PEAR classes are installed as part of the
25php-devel package and under FreeBSD they are installed as part of
59eb67c1 26the mod_php4 or php4 port/package. In Debian, you can install the
27php4-pear package. I'm afraid I have no information on
4dccdc01 28other systems at the present time.
6ff1c690 29
30
31Configuring addressbooks in database
32------------------------------------
33
34First you need to create a database and a table to store the data in.
35Create a database user with access to read and write in that table.
36
37For MySQL you would normally do something like:
38
39 (from the command line)
40 # mysqladmin create squirrelmail
41
42 (from the mysql client)
598294a7 43 mysql> GRANT select,insert,update,delete ON squirrelmail.*
588f1ca4 44 TO squirreluser@localhost IDENTIFIED BY 'sqpassword';
6ff1c690 45
46The table structure should be similar to this (for MySQL):
47
48 CREATE TABLE address (
1e63b430 49 owner varchar(128) DEFAULT '' NOT NULL,
6ff1c690 50 nickname varchar(16) DEFAULT '' NOT NULL,
51 firstname varchar(128) DEFAULT '' NOT NULL,
52 lastname varchar(128) DEFAULT '' NOT NULL,
53 email varchar(128) DEFAULT '' NOT NULL,
54 label varchar(255),
55 PRIMARY KEY (owner,nickname),
56 KEY firstname (firstname,lastname)
57 );
58
7ac2b372 59and similar to this for PostgreSQL:
60CREATE TABLE "address" (
61 "owner" varchar(128) NOT NULL,
62 "nickname" varchar(16) NOT NULL,
63 "firstname" varchar(128) NOT NULL,
64 "lastname" varchar(128) NOT NULL,
65 "email" varchar(128) NOT NULL,
66 "label" varchar(255) NOT NULL,
67 CONSTRAINT "address_pkey" PRIMARY KEY ("nickname", "owner")
68);
69CREATE UNIQUE INDEX "address_firstname_key" ON "address"
70 ("firstname", "lastname");
71
6ff1c690 72
4f40a59d 73Next, edit your configuration so that the address book DSN (Data Source
74Name) is specified, this can be done using either conf.pl or via the
75administration plugin. The DSN should look something like:
6ff1c690 76
98749983 77 mysql://squirreluser:sqpassword@localhost/squirrelmail or
78 pgsql://squirreluser:sqpassword@localhost/squirrelmail
6ff1c690 79
80From now on all users' personal addressbooks will be stored in a
81database.
82
6e00b127 83Global address book uses same table format as the one used for personal
84address book. You can even use same table, if you don't have user named
85'global'.
6ff1c690 86
87Configuring preferences in database
88-----------------------------------
89
3499f99f 90This is done in much the same way as it is for storing your address
91books in a database.
92
93The table structure should be similar to this (for MySQL):
6ff1c690 94
95 CREATE TABLE userprefs (
1e63b430 96 user varchar(128) DEFAULT '' NOT NULL,
6ff1c690 97 prefkey varchar(64) DEFAULT '' NOT NULL,
1e63b430 98 prefval BLOB DEFAULT '' NOT NULL,
6ff1c690 99 PRIMARY KEY (user,prefkey)
100 );
101
7ac2b372 102and for PostgreSQL:
103CREATE TABLE "userprefs" (
98749983 104 "username" varchar(128) NOT NULL,
7ac2b372 105 "prefkey" varchar(64) NOT NULL,
106 "prefval" text,
98749983 107 CONSTRAINT "userprefs_pkey" PRIMARY KEY ("prefkey", "username")
7ac2b372 108);
109
3499f99f 110Next, edit your configuration so that the preferences DSN (Data Source
111Name) is specified, this can be done using either conf.pl or via the
112administration plugin. The DSN should look something like:
113
98749983 114 mysql://squirreluser:sqpassword@localhost/squirrelmail or
115 pgsql://squirreluser:sqpassword@localhost/squirrelmail
3499f99f 116
117From now on all users' personal preferences will be stored in a
118database.
6ff1c690 119
120Default preferences can be set by altering the $default array in
3499f99f 121db_prefs.php.
06316c07 122
123Troubleshooting
124---------------
1251. Oversized field values. Preferences are not/can't be saved
126
127Database fields have size limits. Preference table example sets 128
128character limit to owner field, 64 character limit to preference key
129field and 64KB (database BLOB field size) limit to value field.
130
131If interface tries to insert data without checking field limits, it
132can cause data loss or database errors. Table information functions
133provided by Pear DB libraries are not accurate and some database
134backends don't support them. Since 1.5.1 SquirrelMail provides
135configuration options that set allowed field sizes.
136
137If you see oversized field errors in your error logs - check your
138database structure. Issue can be solved by increasing database field
139sizes.
140
141If you want to get more debugging information - check setKey() function
142in dbPrefs class. Class is stored in functions/db_prefs.php