[英]what is the best approach to insert multple urls which is saved by a perticular user to the database?
i am making a bookmarking site where user saves his urls. 我正在建立一个书签站点,用户可以在其中保存他的网址。 so what is the best approach to insert all urls of a user into a database(mysql). 那么将用户的所有URL插入数据库(mysql)的最佳方法是什么。
1)create individual table for individual user. 1)为个人用户创建个人表。 in each table create 1 column and put 1 url per row(per cell). 在每个表格中创建1列,然后每行(每个单元格)放置1个url。
2) create 1 table and insert all urls into a single cell according to the row of the user. 2)创建1个表,然后根据用户的行将所有url插入单个单元格中。
if 2nd option is best then can anyone explain me how to do it? 如果第二个选项是最好的,那么谁能解释我该怎么做? i can insert one url in one cell but how to insert all urls into a single cell and again retrieve it to display in a proper manner. 我可以在一个单元格中插入一个URL,但是如何将所有URL插入单个单元格,然后再次检索它以适当的方式显示。 Thank you for taking time and reading my question. 感谢您抽出宝贵时间阅读我的问题。 I tried hard to do this myself but failed. 我自己努力做到这一点,但失败了。 that's why asking here. 这就是为什么在这里问。
Create a bookmark
table with the following columns: (id, fk_user_id, url)
. 用以下几列创建一个bookmark
表: (id, fk_user_id, url)
。 Each entry would have its own id, and the foreign-key would be the id of the user. 每个条目将具有其自己的ID,外键将是用户的ID。
You don't want to create an individual table per user. 您不想为每个用户创建一个单独的表。 That won't scale! 那不会扩展! Imagine you have a thousand users - that's at least a thousand tables that you have! 假设您有一千个用户-至少有一千个表!
The second approach could work, but has the following problems: 第二种方法可以工作,但有以下问题:
http://google.com
in the column, and Client #1 wants to add http://reddit.com
and Client #2 wants to add http://stackoverflow.com
. 例如,假设您已经在该栏中添加了http://google.com
,并且客户端#1要添加http://reddit.com
,客户端#2要添加http://stackoverflow.com
。 If Client #2 reads in the value before Client #1's data has been persisted, you will either end up with http://google.com, http://reddit.com
or http://google.com, http://stackoverflow.com
depending on who writes to the table last. 如果客户端#2在持久保存客户端#1的数据之前读入该值,则您将以http://google.com, http://stackoverflow.com
http://google.com, http://reddit.com
或http://google.com, http://stackoverflow.com
结尾http://google.com, http://stackoverflow.com
取决于谁最后写入表。 This could even happen if you get multiple add requests from the same client at close to the same time. 如果您几乎同时从同一客户端收到多个添加请求,甚至可能会发生这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.