[英]Multilang catalog(with custom fields) DB structure design
Soon I'll be working on catalog(php+mysql) that will have multilang content support. 很快,我将研究具有多语言内容支持的目录(php + mysql)。 And now I'm considering the best approach to design the database structure. 现在,我正在考虑设计数据库结构的最佳方法。 At the moment I see 3 ways for multilang handling: 目前,我看到3种多语言处理方式:
1) Having separate tables for each language specific data, ie schematicly it'll look like this: 1)对于每种语言特定的数据都有单独的表,即,示意图看起来像这样:
And here are tables that will be dublicated for each language: 这是每种语言都会被复制的表格:
Pros: 优点:
Cons: 缺点:
2) Using 'lang' field in content tables: 2)在内容表中使用“ lang”字段:
Pros: 优点:
Cons: 缺点:
3) Same as 2nd way, but with Main_Content_Items table merged with Common_Data, that has 'lang' field: 3)与第二种方法相同,但Main_Content_Items表与Common_Data合并,具有“ lang”字段:
Pros: 优点:
Cons: 缺点:
Will be glad to hear suggestions about "what is better" and "why"? 听到关于“什么更好”和“为什么”的建议会很高兴吗? Or are there better ways? 还是有更好的方法?
Thanks in advance... 提前致谢...
I've given a similar anwer in this question and highlighted the advantages of this technique (it would be, for example, important for me to let the application decide on the language and build the query accordingly by only changing the lang
parameter in the WHERE
clause of the SQL query. 我在这个问题上给出了类似的答案,并强调了该技术的优势(例如,对于我来说,让应用程序决定语言并仅通过更改WHERE
的lang
参数来构建查询就很重要。 SQL查询的子句。
This get's pretty close to your second solution. 这非常接近您的第二个解决方案。 I didn't quite got the "extra_fields" but if it makes sense, you could(!) merge it into the common_data table. 我不太了解“ extra_fields”,但如果有道理, 可以将其合并到common_data表中。 I would advise you against the first idea since there will be too many tables and it can be easy to lose track about the items in there. 我建议您不要第一个想法,因为桌子太多了,很容易迷失那里的物品。
To your edit: I still consider the second approach the better one (it's my optinion so it's relative ;)) I'm no expert on optimization but I think that with proper indexes and proper table structure speed should be not be a problem. 编辑:我仍然认为第二种方法更好(这是我的选择,所以是相对的;)我不是优化专家,但我认为拥有适当的索引和适当的表结构速度应该不是问题。 As always, the best way to find the most effective way is doing both methods and see which is best since speed will vary from data, structure, .... 与往常一样,找到最有效方法的最佳方法是同时执行这两种方法,并查看哪种方法最好,因为速度会因数据,结构等而异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.