Fred
Fred

Reputation: 147

How to store chat messages in mysql database?

I am creating a chat application for my website! Now the question is how can i store chat messages on database! How to store chat messages of one specific person in database! Suppose there is a table Username Chat John Hello how are you?

In this case i can only store one message for one person! How can i store multiple message for one person? Suppose: Username Chat John Hello how are you? What's up? Just hanging around!

Please tell me how can i store the messages in database! And also please suggest should i store messages in database or text file?

Upvotes: 0

Views: 3506

Answers (2)

Reza Bojnordi
Reza Bojnordi

Reputation: 667

An example of a communication table for a chat

Primary key table username id In the field replice message the tables edited

enter image description here

Upvotes: 6

Nayas Subramanian
Nayas Subramanian

Reputation: 2379

You can design something like this

Tables

**ChatMaster** (Main table keep chat session details)
ChatId int identity, ChatStartTime datetime, ChatEndTime

**ChatDetails** (To keep chat message details and user from)
ChatDetailsId int identity, ChatMessage varchar(max), ChatId int foreign key, FromUserId int Foreign key, EntryTime datetime, IsActive bit

**ChatUsers** (to users) 
ChatUserId int identity, ChatDetailsId int foreign key, ToUserIds int foreign key

Upvotes: 0

Related Questions