简体   繁体   English

如何构造一个简单的数据库

[英]How to structure a simple database

I would like to construct a database of the following nature: 我想构建一个具有以下性质的数据库:

There are different types of people, and each person does many jobs, example: 有不同类型的人,每个人都有很多工作,例如:

cleaner: clean toilet, clean kitchen 清洁工:清洁厕所,清洁厨房
maid: do laundry, cook breakfast, cook lunch 女佣:洗衣服,做早餐,做午餐
gardener: plant flowers, water flowers 园丁:种花,浇花

I will also have a MySQL database with all of the cleaners, maids, gardeners, etc. The user will write which job he needs into an HTML form and then the PHP file will determine who does the desired job and then select the most appropriate person for the job. 我还将拥有一个包含所有清洁工,女佣,园丁等的MySQL数据库。用户将需要的工作写成HTML表单,然后PHP文件将确定谁做所需的工作,然后选择最合适的人为了工作。

How do I structure the above database? 如何构建以上数据库? Do I do it just as I did above? 我是否像上面那样做?

How does PHP "put them together"? PHP如何“将它们放在一起”? Must I use arrays? 我必须使用数组吗?

Should I put this database directly into the PHP code or in a separate text file (or other kind of file)? 我应该将此数据库直接放入PHP代码中还是放在单独的文本文件(或其他类型的文件)中?

Thanks everyone! 感谢大家!

As indicated in the other post, you need to learn basics before you dive into something complicated. 如另一篇文章所述,您需要先学习基础知识,然后再深入研究复杂的事物。 There are ample tutorials on web which are easy to understands and get started with. 网络上有很多容易理解和入门的教程。

You may start with this tutorial to get a grasp of working with MySQL and PHP, and then you can use the following schema for your web-application. 您可以从本教程开始以掌握使用MySQL和PHP的知识,然后可以将以下模式用于Web应用程序。

people
  people_id (PK)
  name

roles
  role_id (PK)
  role_name

tasks
  task_id (PK)
  role_id (FK)
  task_desc

people_roles
  pr_id (PK)
  people_id (FK)
  role_id (FK)
  • people -- all the employees/people and their details people -所有员工/人员及其详细信息

  • roles -- all the available roles roles -所有可用角色

  • tasks -- tasks that each role is assigned, role and task has one to many relationship (see the FK?) tasks -为每个角色分配的taskroletask具有一对多关系(请参阅FK?)

  • people_roles -- this is a link table that makes may-to-many relation ship between people and roles , so that a gardener can be act as a cook . people_roles -这是一个链接表,使得5月间到多的关系船peopleroles ,让园丁可以充当厨师 If you wish to assign so. 如果您希望分配。

Hope this helps. 希望这可以帮助。

You need to learn to walk before you can run. 您需要学习走路后才能跑步。

I would do some basic PHP/MySQL tutorials first to get yourself familiar with the very basics of data manipulation. 我将首先做一些基本的PHP / MySQL教程,以使您熟悉数据操作的基础知识。 Then maybe to speed up production use a framework, CakePHP would by my recommendation based on it's powerful auto-magic CRUD (Create, Read, Update, Delete - something else to read up on :) ). 然后也许为了加快使用框架的生产速度,根据我的建议, CakePHP将基于它强大的自动魔术CRUD(创建,读取,更新,删除- 其他需要阅读的内容:) )。

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

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