How do you know how to create mysql database when creating advanced php application?

I never created a shopping cart or forum in php. in addition to viewing and analyzing the project of others or viewing textbooks that show how to make such a project or how to be such a project. how would a person know how to create a database structure to create such a thing? im guessing it, probably through trial and error ...

+6
database php mysql structure
source share
3 answers

The basic method that you can learn about database design is called Database Normalization .

Database normalization is limited, especially if you have a lot of transactions. At some point, you may be forced to Denormalize .

But IMHO it is always better to start with a normal database design.

+3
source share

You must read and understand the basics of normalization . For most projects, normalizing to the 3rd normal form will be fine. There are always certain scenarios when you want to normalize more or less, but understanding the concepts underlying it will allow you to think about how your database is structured in a normalized format.

here is a very simple example of table normalization:

students student_id student_name student_class student_grade 

a pretty standard table containing various data, but we can immediately see some problems. we can see that the student’s name depends on its identifier, however, the student can participate in several classes, and each class may have a different class. we can then think of tables as such:

 students student_id student_name class class_id class_name 

This is not bad, now we can see that we have different students and different classes, but we did not study students' grades.

 grades student_id class_id grade 

we now have a third table that allows us to understand the relationship between a particular student, a specific class, and the class associated with that class. from our first source table we now have 3 tables in the normalized database (let's say that we do not need to normalize the estimates for example :))

A few things we can learn from this very simple example:

  • our data is bound to a specific key (student_id, class_id and student_id + class_id). these are unique identifiers in each table.
  • with our key relationships, we can relate information to each other (how many classes do students in number 4096 study in?)
  • we can see that our tables now do not contain duplicate data (think of our first table, where student_class can be the same value for many students. If we had to change the class name, we would have to update all records in our normalized format we can just update class_name of class_id)
+17
source share

I would also recommend using a visual editor to create a database schema. I recently used: http://dev.mysql.com/workbench/

Once you create a database project, ask someone who has more experience to look at it and give you feedback. But know that as much time as you can spend on design, you will eventually have to complete the implementation, and you will find out that you are missing something or you can do even better work by doing it differently.

So create, get feedback, but don't be afraid to change.

+1
source share

All Articles