I'm building my own authentication system. Right now I have my database setup to log each login timestamp by:
$query = 'UPDATE `users` SET login_log = concat(login_log, ?) WHERE userKey = ? LIMIT 1 ';
$vars = array(time().',', $this->userKey);
$QH = $this->DBH->prepare($query);
$QH->execute($vars);
Is it bad to use concat()
to log data in longtext
field?
The only thing I can think of offhand is that unless there is a business need to only have one field of login_log, there is no reason to concatenate, especially if you want to perform a constraint against the time portion thereafter...you'd have to parse out of all of the other log text (here the other times) before getting the time() component you wanted.
You could much easier normalize your data and add an autoincrementing int PK, followed by a userKey field and a login_LogDate field. After each login, you could insert into users table the user name and the current time. You could then easily find the min, max, top Nth login, etc. much easier than splitting it out.
精彩评论