Giải pháp thiết kế web động với PHP - p 31

GETTING STARTED WITH MYSQL How a database stores information All the data in MySQL is stored in tables, very much in the same way as in a spreadsheet, with information organized into rows and columns. Figure 10-1 shows the database table that you will build later in this chapter, as displayed in phpMyAdmin. Figure 10-1. A database table stores information in rows and columns like in a spreadsheet. Each column has a name (image_id, filename, and caption) indicating what it stores. The rows aren t labeled, but the first column (image_id) contains a unique value known as a primary key, which identifies the. | GETTING STARTED WITH MYSQL How a database stores information All the data in MySQL is stored in tables very much in the same way as in a spreadsheet with information organized into rows and columns. Figure 10-1 shows the database table that you will build later in this chapter as displayed in phpMyAdmin. Record Column Field Primary key Figure 10-1. A database table stores information in rows and columns like in a spreadsheet. Each column has a name image_id filename and caption indicating what it stores. The rows aren t labeled but the first column image_id contains a unique value known as a primary key which identifies the data associated with the row. Each row contains an individual record of related data. The intersection of a row and a column where the data is stored is called a field. For instance the caption field for the third record in Figure 10-1 contains the value The Golden Pavilion in Kyoto and the primary key for that record is 3. The terms field and column are often used interchangeably particularly by phpMyAdmin. A field holds one piece of information for a single record whereas a column contains the same field for all records. How primary keys work Although Figure 10-1 shows image_id as a consecutive sequence from 1 to 8 they re not row numbers. Figure 10-2 shows the same table with the captions sorted in alphabetical order. The field highlighted in Figure 10-1 has moved to the seventh row but it still has the same image_id and filename. 281 CHAPTER 10 Now in the seventh row but imagejd -remains unchanged Download from Wow eBook Figure 10-2. The primary key identifies the row even when the table is sorted in a different order. Although the primary key is rarely displayed it identifies the record and all the data stored in it. Once you know the primary key of a record you can update it delete it or use it to display data in a separate page. Don t worry about how you find the primary key. It s easily done using Structured Query .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.