dongren7374 2016-07-21 23:34
浏览 31
已采纳

存储自定义/不同的用户数据

If I was to create a data collection application which enabled the user to collect multiple data types what would be the best way to store the customised data?

I. E. User 1 might want to store username, email, address while user 2 might want to store username, password and phone number.

Obviously these data types are different and one table cannot accommodate for the differences according to column based design, what would be the best way to accommodate for this?

  • 写回答

1条回答 默认 最新

  • dronthpi05943 2016-07-22 00:02
    关注

    This is a very common scenario because many sites will allow you to fill out your profile with as much or as little info as you want (besides required fields), so they need flexible storage. These options come to mind immediately:

    Option 1

    If you need a way to filter, sort or otherwise process these attributes quickly, a DB table is still your best bet. You don't need to worry about putting different data types in the same column: Have a username column, a phone column, an email column... When you design the table, just allow optional fields to be NULL and leave them empty when you don't have the info.

    Option 2

    If you just want to store the info, you could use XML or JSON formats. These are really flexible, and will allow you to store any data you want, either in individual files (each user has matching file), in one big file, or again in a DB table with just an id, a username and a generic userdata column that will store the data. When you need the data, just open the file or query the DB and unpack it with simplexml_load_string or json_decode function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错