开发者

SQL, Is it bad to concat() log data in longtext field?

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?

Should I be doing this a diff开发者_如何学Pythonerent way?

Are there any problems I might run into down the road with this method?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜