Chapter 7:design your Web database
In this chapter, we need-discuss three problems in order-get-into-MySQL specifics in the next chapter:
[1] ralational Database concepts and terminology (databases related concepts and terminology)
[2] Web database design
[3] Web databse Architecture (schema of the database)
The first problem:ralational database concepts
[Tables]
A table should hava a table_name, a number of columns, a number of rows, each col was corresponding to a different piece of Data, each row is corresponding to an individual data.
(a table has table name, column, row, each column corresponds to different data, each row corresponds to a property of the data)
[Columns]
Each column of the table has a unique name and contains different data.
Each column has a associated data type.
Because of this, columns is sometimes called fields or attributes.
(columns are often referred to as "domains" or "properties")
[Rows]
Each row has the same data type and the same attributes.
Because of this, rows is called records or tuples.
(rows are often referred to as "records" or "tuples")
[Values]
Each row consists of a set of individual values, correspond to columns.
Each value must has the data type specified by its column.
(each row consists of a single value corresponding to each column (where the row and column intersect is the value); Each value must be the same as the data type defined by the column)
[Keys]
Key is a-to-identify each specific data.
The identifying column in a table is called the key or the primary key.
A key can consist of multiple columns.
Databases usually consist of multiple tables and use a key as a reference from one
Table to another.
[Schemas]
Schemas mean that, the complete set of the table designs for a database.
[Ralationships]
Foreign keys represent a relationship between data in both tables.
Relationships can be either one-to-one, one-to-many, or Many-to-many.
The second Problem:web database design
[1] Think about the real world objects is modeling (considering the true object to model)
[2] Avoid storing redundant data (avoid duplication)
[3] Use atomic column values (using atomic column value)
[4] Choose sensible keys (select meaningful primary key)
[5] Think about the questions your want to ask the database (we want to solve the problem with this db)
[6] Avoid designs with many empty attribute s (avoid null values)
The third Problem:web database architecture
[1] A user ' s web browser issues an HTTP request for A particular Web page.
[2] The WEB server receives the request, retrieves the file (xxx.php), then passes it to the PHP engine for processing.
[3] The PHP engine begins parsing the script. PHP opens the connection to the MySQL server and sends on the appropriate query.
[4] The MySQL server receives the database query and process it, and sends the results back to the PHP engine.
[5] The PHP engine finishes running the script, which'll usually involve formatting the query results nicely in HTML. It then returns the resulting HTML to the WEB server.
[6] The WEB server passes the HTML back to the browser.
A simple summary of designing a Web database