Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
PHP Programming With MySQL Second Edition.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
43.07 Mб
Скачать

CHAPTER 7

Working with Databases and MySQL

432

The fourth option under the MySQL column header is “Databases”.

Clicking this option opens a page with four tabs across the top of the

screen, and a list of the available databases beneath. Clicking a data-

base name from the list opens the Structure page for that database.

On this screen, you can drop and modify existing tables in the list.

You can also create new tables and rename the database using the

fields beneath the list.

Working with Tables

Once you have selected the database, any tables in that database are

listed on the left side of the screen. To view the table structure, click

the Properties icon from the table list of the database screen, or click

the table name on the left side of the screen. The Structure page

opens for the selected table. On this screen, you can drop and modify

existing fields in the list. You can also create new fields and indexes

using the fields beneath the list.

Click the Browse tab to open the Browse page for the selected table.

This page allows you to view, edit, and delete records in the table.

Click the Insert tab to open the Insert page for the selected table. This

page allows you to add records to the table.

The last two tabs, Empty and Drop, are shown in red for two reasons.

First, they do not take you to a separate Web page. Second, and more

Important, these two tabs can cause you to lose all of the data in the

table. Therefore, you should only click these two tabs when you are

sure that you want to delete all records from the table or remove the

table from the database.

Exporting and Importing Tables

The Export tab on the Table Web page allows you to automatically

generate a SQL script with all of the SQL commands to create and

populate the table with all of the existing data. This is convenient

when you want to move an entire table from one database to another.

For example, you could do all of the exercises in this chapter in a local

MySQL database. When finished, you could export all of the tables

and import them in the MySQL database on the remote server for

your instructor to review.

To export the table and data, click the SQL radio button in the Export

list. The default “SQL options” settings do not need to be changed.

Click the “Save as file” check box, ensuring that the box is checked.

Click the Go button to have phpMyAdmin generate the script. The

next step varies depending on the browser you are using. In Mozilla

Summing Up

Firefox, click the “Save file” radio button in the next dialog box and

click OK. The file is automatically saved to a Downloads folder with

the active database assigned as the filename and an .sql extension.

Remember the name and location of your download. If you are using

Internet Explorer to export the table, click the Save button in the File

Download dialog box and navigate to the location where you want to

save the file. The filename will be the name of the active table with an

.sql extension.

To import the table and data, navigate to the Database page for the

destination database. Click the SQL tab, which displays the Run SQL

query screen for that database. In the lower section, click the Browse

button to display the File Upload dialog box. Navigate to the file

that you exported (it will have an .sql extension), and click the Open

button. When you click the Go button in the lower-right corner of

the screen, phpMyAdmin will load and run the script file. When

completed, phpMyAdmin shows the imported script, and the table

appears in the list on the left side of the screen. If the import is suc-

cessful, a message appears at the top of the window: “Your SQL-query

has been executed successfully”. If the table could not be imported, a

message appears and describes the error. Click the Structure tab to

verify that the imported table now appears in the list of tables for the

schema.

Because the

exported file

is an SQL

script, you

use the SQL tab to run

the script that creates the

table and inserts the data.

The Import tab is used

when importing delimited

text files, much like using

the LOAD DATA

command in MySQL

Monitor.

433

Short Quiz

1.

What message is displayed at the database page if the user has

not been assigned the privilege to create new databases?

Thetab from the table page displays the

records in the selected table.

Describe the process of exporting the structure and contents

of a table from one database and importing it into another

database using the phpMyAdmin tool.

2.

3.

Summing Up

• A database is an ordered collection of information that a computer

program can quickly access.

• A record in a database is a single, complete set of related

information.


CHAPTER 7

Working with Databases and MySQL

• Fields are the individual categories of information stored in a record.

• A flat-file database stores information in a single table.

• A relational database stores information across multiple related tables.

434

• A query is a structured set of instructions and criteria for retriev-

ing, adding, modifying, and deleting database information.

• Structured query language, or SQL (pronounced sequel ), is a

standard data manipulation language among many database

management systems.

• MySQL Monitor is a command-line program that you use to

manipulate MySQL databases.

• To work with a database, you must first select it by executing the

USE database statement.

• You use the

CREATE DATABASE statement to create a new database.

• To delete a database, you execute the

DROP DATABASE state-

ment, which removes all tables from the database and deletes the

database itself.

• The fields in a table also store data according to type. To keep your

database from growing too large, you should choose the smallest

data type possible for each field.

• To create a table, you use the

CREATE TABLE statement, which

specifies the table and column names and the data type for

each column.

• To modify a table, you use the

ALTER TABLE statement, which spec-
Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]