最佳 OOP 实践 PHP/MySQL
我正在创建一个单词老师:
我创建了一个包含多个表的数据库:
TblTheme (themeId, name);<br>
TblGroup (groupId, name, themeIdFK);<br>
TblWeek (weekId, week, groupIdFK);<br>
tblWord (wordId, word, weekIdFK);<br>
所以 themeIdFK、groupIdFK 和 weekIdFK 是外键。
在 PHP 中我想显示所有主题。如果按下主题,则显示所有组等。 我应该创建什么类。 (如课程主题、小组、周和单词) 在不使数据库超载的情况下检索数据的最佳方法是什么?
I am creating a word teacher:
I created a database with multiple tables:
TblTheme (themeId, name);<br>
TblGroup (groupId, name, themeIdFK);<br>
TblWeek (weekId, week, groupIdFK);<br>
tblWord (wordId, word, weekIdFK);<br>
So themeIdFK, groupIdFK and weekIdFK are Foreign keys.
In PHP i want to show all the themes. If a theme is pressed, show all the groups etc..
What classes should i create. (like classes Theme, group, week and word)
and what is the best way to retrieve the data, without overloading the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果列包含相同的数据,那么它应该具有相同的名称:
然后当您创建 JOIN 时,您可以将其写为
至于您原来的问题:
我会选择课程:
基本上这个设置将实现 DataMapper 模式。
为每个表创建一个类是没有意义的,因为附加表仅保存有关单词的信息。至少我是这么看的。
不过,我不太确定您是否需要制作一个复杂的应用程序,只是为了制作日常用语......也许只是作为练习。
First of all , if column holds same data , then it should have the same name:
Then when you create JOIN , you can write it as
As for you original question :
I would go with classes :
Basically this setup would implement DataMapper pattern.
There is no point in making a class per table, because the additional tables are only holding info about the Words. At lest that's how i see it.
Though, I'm not so sure if you need to make a complex App, just for making word-of-day thing .. maybe only as exercise.