tailieunhanh - Giải pháp thiết kế web động với PHP - p 33
GETTING STARTED WITH MYSQL MySQL timestamps are based on a human-readable date and, since MySQL , use the same format as DATETIME. As a result, they are incompatible with Unix and PHP timestamps, which are based on the number of seconds elapsed since January 1, 1970. Don t mix them. Storing predefined lists MySQL lets you store two types of predefined list that could be regarded as the database equivalents of radio button and check box states: • • ENUM: This column type stores a single choice from a predefined list, such as “yes, no, don t know” or “male, female.” The maximum number of items. | GETTING STARTED WITH MYSQL MySQL timestamps are based on a human-readable date and since MySQL use the same format as DATETIME. As a result they are incompatible with Unix and PHP timestamps which are based on the number of seconds elapsed since January 1 1970. Don t mix them. Storing predefined lists MySQL lets you store two types of predefined list that could be regarded as the database equivalents of radio button and check box states ENUM This column type stores a single choice from a predefined list such as yes no don t know or male female. The maximum number of items that can be stored in the predefined list is a mind-boggling 65 535 some radio-button group SET This column type stores zero or more choices from a predefined list. The list can hold a maximum of 64 choices. While ENUM is quite useful SET tends to be less so mainly because it violates the principle of storing only one piece of information in a field. The type of situation where it can be useful is when recording optional extras on a car or multiple choices in a survey. Storing binary data Storing binary data such as images isn t a good idea. It bloats your database and you can t display images directly from a database. However the following column types are designed for binary data TINYBLOB Up to 255 bytes BLOB Up to 64kB MEDIUMBLOB Up to 16MB LONGBLOB Up to 4GB With such whimsical names it s a bit of a letdown to discover that BLOB stands for binary large object. Chapter review Much of this chapter has been devoted to theory explaining the basic principles of good database design. Instead of putting all the information you want to store in a single large table like a spreadsheet you need to plan the structure of your database carefully moving repetitive information into separate tables. As long as you give each record in a table a unique identifier its primary key you can keep track of information and link it to related records in other tables through the use of foreign keys. The concept of .
đang nạp các trang xem trước