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

Introduction to Databases

formats. A DBMS that stores data in a flat-file format is called a

flat-file database management system. A DBMS that stores data

In a relational format is called a relational database management

system, or RDBMS. Other types of DBMSs are hierarchical and net-

work database management systems. In addition to the open source

MySQL DBMS, some of the more popular relational DBMSs include

Oracle, Sybase, and SQL Server for network servers, and Microsoft

Access and Paradox for PCs.

Database management systems perform many of the same functions

as other types of applications you might have encountered, such as

word-processing and spreadsheet programs. For example, a DBMS

creates new database files and contains interfaces that allow users to

enter and manipulate data. One of the most important functions of

a DBMS is the structuring and maintenance of the database file. In

addition, a DBMS must ensure that data is stored correctly in a data-

base’s tables, regardless of the database format (flat-file, relational,

hierarchical, or network). In relational databases, the DBMS ensures

that the appropriate information is entered according to the relation-

ship structure in the database tables. Many DBMSs also have security

features that restrict user access to specific data.

Another important aspect of a DBMS is its querying capability.

A query is a structured set of instructions and criteria for retrieving,

adding, modifying, and deleting database information. Most database

management systems use a data manipulation language, or DML, for

creating queries. Different DBMSs support different DMLs. However,

structured query language, or SQL (sometimes pronounced sequel),

Is a standard data manipulation language among many dbmSs.

Many DBMSs include tools that make it easier to build queries.

MySQL includes MySQL Query Browser, a tool that allows you to

work with MySQL queries in a graphical environment. You can use

MySQL Query Browser to create queries by typing SQL commands

Into the query area at the top of the screen or by dragging tables and

fields from the Schemata area to the query area.

Although working with an interface to design queries is helpful, you

must still use the DBMS’s data manipulation language (for example,

when accessing databases with PHP). Because SQL is the underlying

data manipulation language for many DBMSs, including MySQL, you

will learn more about the language as you progress through this chapter.

It is important to understand that even though many dbmSs sup-

port the same database structures (flat-file, relational, hierarchical, or

network), each DBMS is an individual application that creates its own

proprietary file types. For example, even though Access and Paradox

are both relational DBMSs, Access creates its database files in a

PostgreSQL is

another open

source rela-

tional DBMS

that is becom-

ing a popular alternative

to MySQL. You can find

more information on

PostgreSQL at http://

www.postgresql.org/.

389

Many DBMSs

also use

a data

definition

language,

or DDL, for creating

databases, tables, fields,

and other database

components.


CHAPTER 7

Working with Databases and MySQL

390

proprietary format with an .accdb extension (.mdb for Access 2003

and earlier), whereas Paradox creates a set of database files in a differ-

ent proprietary format, with the data stored in files with a .db exten-

sion. Although both Paradox and Access contain filters that allow you

to import the other’s file formats, the database files are not completely

interchangeable between the two programs. The same is true for most

DBMSs; they can import each other’s file formats, but they cannot

directly read each other’s files.

In today’s ever-evolving technology environment, an application

must often access multiple databases created in different DBMSs.

For example, a company might need a PHP script that simultane-

ously accesses a large legacy database written in Sybase and a newer

database written in Oracle. Converting the large Sybase database to

Oracle would be cost prohibitive. On the other hand, the company

cannot continue using the older Sybase database exclusively because

its needs have grown beyond the older database’s capabilities. So, the

company must be able to access the data in both systems.

To allow easy access to data in various database formats, Microsoft

established the Open Database Connectivity standard (ODBC).

ODBC allows compliant applications to access any data source for

which there is an ODBC driver. ODBC uses SQL commands (known

as ODBC SQL) to allow an ODBC-compliant application to access

a database. Essentially, an ODBC application connects to a database

for which there is an ODBC driver and then executes ODBC SQL

commands. Then, the ODBC driver translates the SQL commands

into a format that the database can understand. PHP includes strong

support for ODBC, and includes functionality that allows you to

work directly with different types of databases without going through

ODBC. Some of the databases that you can access directly from PHP

include Oracle, Informix, MySQL, and PostgreSQL. By eliminating

the ODBC layer, your PHP scripts will be faster. Furthermore, PHP

code that directly accesses a database allows you to access proprietary

DBMS functions that are not supported by ODBC. Therefore, your

rule of thumb should be to always use direct database access if it is

available in PHP. Otherwise, use PHP’s ODBC functionality to access

ODBC-compliant databases.

In Chapter 8,

you will learn

how to use

PHP to

access

MySQL databases

directly.

Querying Databases with Structured Query

Language (SQL)

Programmers at IBM developed SQL in the 1970s as a way to query

databases for specific criteria. Since then, SQL has been adopted by

numerous DBMSs running on mainframes, minicomputers, and PCs.

In 1986, the American National Standards Institute (ANSI) approved


Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]