问题描述:

I have loginlog table as following

Field Type

login_id int(10) NOT NULL

platform varchar(50) NOT NULL

browser varchar(50) NOT NULL

ipaddress varchar(50) NOT NULL

last_login datetime NULL

last_logout datetime NULL

But on this structure I am confuse that I can add login time but its hard to update it for logout time. I have not added primary key because logs are frequent and primarykey will soon reach it max value. What should be the best way? Please help.

网友答案:

Having a single row with both login and logout like that is just asking for trouble, because it assumes that every login has a corresponding logout, which is just not the case. Sometimes they will login on a public computer and never log out, sometimes they will open an anonymous window and login.

Instead, I would cut it down to just a type:

  • login_id
  • platform
  • browser
  • ip_address
  • date
  • type (login / logout)
网友答案:

Why not just create table logout log, with 2 columns.
with a reference to corresponding login_id, and the time of logout.

And last_login, and last_logout do not make sense to me, but your logic may require it. Because IMO you should avoid having columns, which can have NULL.

EDIT: As a addon, I would say why would you accumulate so much data. If it is only for analyzing user's browser, platform, you can use Google Analytics. And you can just keep last_login, and last_logout for each user, then. Again, your business logic may require it.

网友答案:

my suggestion is that if you want information of last log in and last log out only then.... make the user_id as primary key... and just change that information instead add new record... you can add one count field to enhance your functionality... to get number of count the person is log in...

and if you want each and every login data... just go with the serialization concept... it will help... make array set count as key and your last login, logout, browser as a value of array...serialize that and store in database...

网友答案:

My suggestion is to update entry for each user once he/she relogins to avoid primary key reaching its max value.

相关阅读:
Top