开发者

Database architecture of newsletter service (with php)

开发者 https://www.devze.com 2023-03-13 20:29 出处:网络
I am building a service which provides a newsletter system for the users. My question is, how to organize it on the database? user opens account -> there is a news row on the data base -> how the ema

I am building a service which provides a newsletter system for the users.

My question is, how to organize it on the database? user opens account -> there is a news row on the data base -> how the email will be stored? I thought about something like:

user@mail.com,HASHCODE|user2@anothermail.com,HASHCODE|someone@mail.com,HASHCODE ..

(that will be stored on one field of the user's row, HASHCODE for remove the email)

Then using explode() to order it in an array. but I don't know if it's the best开发者_JAVA百科 way to order the mails.. what do you think?


Why don't you store emails in separate table UserEmails and make a relationship with user table. For starting point you may look at this link Useremail table will have three fields UseremailID email UserID

UseremailID    email         UserID
1           sss@ss.com        1
2           asasf@ssf.com     1

I would recommend you to read some relational database so that you get some idea about tables and relationships


You should consider using a table structure like this:

Table 'subscription'
id int(20) PK auto_increment
email varchar(100) UNIQUE index

This will cause you having to insert a new row into the table with a ID and a e-mailaddress (which will both be unique so you dont get double records)


I would create a table to store the newsletters and another one to create the relation between users and newsletters so you'll have a better control over your information.

Three tables: User, User_Newsletter, Newsletter

The User_Newsletter will only store the user_id and newsletter_id


Database services don't seem to be so flexible (even though they were introduced to be). Normal UNIX filesystem hierarchy and plaintext files are the best way to store information. You don't know the internal structure of a database. But you know everything about your filesystem, including the file permissions and encryption

For example, take Croud Mail, a free e-mail newsletter service from me. I don't use databases, but it the coding is very flexible and safe.

0

精彩评论

暂无评论...
验证码 换一张
取 消