Add templates for message highlighting.
[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
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
26the mod_php4 or php4 port/package. In Debian, you can install the
27php4-pear package. I'm afraid I have no information on
28other systems at the present time.
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)
43 mysql> GRANT select,insert,update,delete ON squirrelmail.*
44 TO squirreluser@localhost IDENTIFIED BY 'sqpassword';
45
46The table structure should be similar to this (for MySQL):
47
48 CREATE TABLE address (
49 owner varchar(128) DEFAULT '' NOT NULL,
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
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
72
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:
76
77 mysql://squirreluser:sqpassword@localhost/squirrelmail or
78 pgsql://squirreluser:sqpassword@localhost/squirrelmail
79
80From now on all users' personal addressbooks will be stored in a
81database.
82
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'.
86
87Configuring preferences in database
88-----------------------------------
89
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):
94
95 CREATE TABLE userprefs (
96 user varchar(128) DEFAULT '' NOT NULL,
97 prefkey varchar(64) DEFAULT '' NOT NULL,
98 prefval BLOB DEFAULT '' NOT NULL,
99 PRIMARY KEY (user,prefkey)
100 );
101
102and for PostgreSQL:
103CREATE TABLE "userprefs" (
104 "username" varchar(128) NOT NULL,
105 "prefkey" varchar(64) NOT NULL,
106 "prefval" text,
107 CONSTRAINT "userprefs_pkey" PRIMARY KEY ("prefkey", "username")
108);
109
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
114 mysql://squirreluser:sqpassword@localhost/squirrelmail or
115 pgsql://squirreluser:sqpassword@localhost/squirrelmail
116
117Note that when using the above PostgreSQL schema, you also need to change
118the prefs_user_field variable in config.php from the default 'user' to
119'username'.
120
121From now on all users' personal preferences will be stored in a
122database.
123
124Default preferences can be set by altering the $default array in
125db_prefs.php.
126
127Troubleshooting
128---------------
1291. Oversized field values. Preferences are not/can't be saved
130
131Database fields have size limits. Preference table example sets 128
132character limit to owner field, 64 character limit to preference key
133field and 64KB (database BLOB field size) limit to value field.
134
135If interface tries to insert data without checking field limits, it
136can cause data loss or database errors. Table information functions
137provided by Pear DB libraries are not accurate and some database
138backends don't support them. Since 1.5.1 SquirrelMail provides
139configuration options that set allowed field sizes.
140
141If you see oversized field errors in your error logs - check your
142database structure. Issue can be solved by increasing database field
143sizes.
144
145If you want to get more debugging information - check setKey() function
146in dbPrefs class. Class is stored in functions/db_prefs.php