PHP 5/MySQL Programming- P69 ppsx

5 287 0
PHP 5/MySQL Programming- P69 ppsx

Đang tải... (xem toàn văn)

Thông tin tài liệu

318 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r Check this site out sometime when you’re bored: http://home.hiwaay.net/~lkseitz/ comics/herogen/. Special thanks to Lee Seitz and his hysterical Super-Hero generator. Editing Table Data You can use phpMyAdmin to browse your table in a format much like a spread- sheet. Figure 9.12 illustrates this capability. Follow these steps to edit a table in phpMyAdmin: 1. Select the table from the table list on the left side of the SQL screen. The table appears in a spreadsheet-like format in the main part of the screen. You can edit the contents of the table in this window. 2. Edit or delete a record by clicking the appropriate icon displayed near the record. 3. Add a row by clicking the corresponding link near the bottom of the table. 4. Leave the cell you edited or press the Enter key. Any changes you make on the table data are automatically converted into the appropriate SQL code. TRICK FIGURE 9.12 Use the Browse tab to view table data. Exporting a Table Some of phpMyAdmin’s most interesting features involve exporting table infor- mation. You can generate a number of data formats. The Export tab looks like the page in Figure 9.13. You might prefer to have your results saved in some sort of delimited format such as those discussed in chapter 6, “Working with Files.” You can easily generate such a format by choosing the Comma-Separated Value (CSV) option and select- ing your delimiters. This is a good choice in these situations: • You want your data to be readable by a spreadsheet. • You are writing a program that can handle such a format but cannot directly access databases. The Excel CSV format configures the data so an Excel spreadsheet can read it eas- ily. The ordinary CSV format allows you to modify your output with a number of options. Figure 9.14 illustrates the CSV version of the hero data set. Once you’ve created your data file, either save it using the appropriate link or copy and paste it to a spreadsheet. Most spreadsheet programs can read various forms of CSV data with minimal configuration. Figure 9.15 demonstrates the file as seen by Microsoft Excel. 319 C h a p t e r 9U s i n g M y S Q L t o C r e a t e D a t a b a s e s FIGURE 9.13 The Export Result Set dialog box allows you to save table data in a number of formats. You can also set up an XML file to hold the data. As you recall from chapter 8, “XML and Content Management Systems,” XML is much like HTML and describes the information in a self-documenting form, as you can see in Figure 9.16. 320 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r FIGURE 9.14 You can print CSV summaries of your data results. FIGURE 9.15 I set up the data as a tab delimited file and read it into Excel. You might use the XML feature to store a database as an XML file and then have a program read that file using XML techniques. This is a good way to work with a database even when the program can’t directly deal with the database server. One last very useful export option: the SQL format. You can use this tool to auto- matically generate an SQL script for creating and populating a table. The SQL formatting utility is useful if you use the visual tools for creating and editing a table, but then want to re-create the table through a script. The dialog box shown in Figure 9.17 illustrates this tool’s various options. You can specify whether the resulting script generates the table structure alone or adds the data. You can also specify whether the resulting script contains code to select a database, drop the specified table if it already exists, and the filename of the resulting script. Figure 9.18 shows the code that might result from an SQL export of the hero table. The ability to automatically generate SQL scripts is incredibly powerful. It can be a great timesaver and you can learn a lot by examining the scripts written with such a feature. However, you are still the programmer and are responsible for code in your projects—even if you didn’t write it directly. You must understand what the generated code does. Most of the code so far is stuff I’ve already described, but you may have to look up advanced features. As I’ve said: Know how to do this stuff by hand. TRAP TRICK 321 C h a p t e r 9U s i n g M y S Q L t o C r e a t e D a t a b a s e s FIGURE 9.16 The XML form of the data generates HTML-like tags to describe the fields. Creating More-Powerful Queries So far, the tables you’ve created haven’t been any more powerful than HTML tables and they’re a lot more trouble. The excitement of databases comes when you use the information to solve problems. Ironically, the most important part of database work isn’t usually getting the data, but filtering the data in order to solve some sort of problem. 322 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r FIGURE 9.17 From this screen you can generate code that manufactures replicas of any database created or viewed with phpMyAdmin. FIGURE 9.18 This code can be run on any MySQL server to make a copy of the hero database. . Table Data You can use phpMyAdmin to browse your table in a format much like a spread- sheet. Figure 9.12 illustrates this capability. Follow these steps to edit a table in phpMyAdmin: 1. Select. appropriate SQL code. TRICK FIGURE 9.12 Use the Browse tab to view table data. Exporting a Table Some of phpMyAdmin’s most interesting features involve exporting table infor- mation. You can generate a. screen you can generate code that manufactures replicas of any database created or viewed with phpMyAdmin. FIGURE 9.18 This code can be run on any MySQL server to make a copy of the hero database.

Ngày đăng: 07/07/2014, 02:20

Mục lục

  • PHP 5 / MySQL Programming for the Absolute Beginner

    • Cover

    • Contents

    • Introduction

    • Chapter 1: Exploring the PHP Environment

    • Chapter 2: Using Variables and Input

    • Chapter 3: Controlling Your Code with Conditions and Functions

    • Chapter 4: Loops and Arrays

    • Chapter 5: Better Arrays and String Handling

    • Chapter 6: Working with Files

    • Chapter 7: Writing Programs with Objects

    • Chapter 8: XML and Content Management Systems

    • Chapter 9: Using MySQL to Create Databases

    • Chapter 10: Connecting to Databases within PHP

    • Chapter 11: Data Normalization

    • Chapter 12: Building a Three-Tiered Data Application

    • Index

    • Team DDU

Tài liệu cùng người dùng

Tài liệu liên quan