简体   繁体   English

SQL,concat()在longtext字段中记录数据是否不好?

[英]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? 使用concat()longtext字段中记录数据是否不好?
Should I be doing this a different 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. 我唯一能想到的就是,除非业务只需要一个login_log字段,否则就没有理由进行串联,尤其是如果您希望对之后的时间部分执行约束...必须先解析所有其他日志文本(此处为其他时间),然后才能获取所需的time()组件。

You could much easier normalize your data and add an autoincrementing int PK, followed by a userKey field and a login_LogDate field. 您可以更轻松地规范化数据并添加一个自动递增的int PK,然后添加一个userKey字段和一个login_LogDate字段。 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. 然后,您可以轻松地找到“最小”,“最大”,“前N个登录名”等信息,这比拆分出来要容易得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM