1. Trang chủ
  2. » Công Nghệ Thông Tin

Beginning PHP and MySQL From Novice to Professional phần 10 ppsx

108 378 0

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Importing and Exporting Data
Trường học Unknown
Chuyên ngành Computer Science
Thể loại Chương
Năm xuất bản 2008
Định dạng
Số trang 108
Dung lượng 4,18 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Importing Data with LOAD DATA INFILE The LOAD DATA INFILE statement, a command that is executed much like a query is executed within the mysql client, is used to import delimited text fi

Trang 3

■ ■ ■

C H A P T E R 3 8

Importing and Exporting Data

Back in the Stone Age, cavemen never really had any issues with data incompatibility,

as stones and one’s own memory were the only storage medium Copying data involved

pulling out the old chisel and getting busy on a new slab of granite Now, of course,

the situation is much different Hundreds of data storage strategies exist, the most

commonplace of which include spreadsheets and various types of databases Working in

a complex, often convoluted fashion, you often need to convert data from one storage

type to another, say between a spreadsheet and a relational database, or between an

Oracle database and MySQL If this is done poorly, you could spend hours, and even

days and weeks, massaging the converted data into a usable format This chapter

seeks to eliminate that conundrum, by introducing MySQL’s data import and export

utilities, as well as various techniques and concepts central to lessening the pain

involved in performing such tasks

By the conclusion of this chapter, you will be familiar with the following topics:

• Common data-formatting standards recognized by most mainstream storage

products

• The SELECT INTO OUTFILE SQL statement

• The LOAD DATA INFILE SQL statement

• The mysqlimport utility

• How to use PHP to mimic MySQL’s built-in import utilities

Before delving into the core topics, take a moment to review the sample data used

as the basis for examples presented in this chapter Afterward, several basic concepts

surrounding MySQL’s import and export strategies are introduced

Trang 4

Sample Table

If you would like to execute the examples as you proceed through the chapter, the following sales table will be the focus of several examples in this chapter:

CREATE TABLE sales (

id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,

client_id SMALLINT UNSIGNED NOT NULL,

order_time TIMESTAMP NOT NULL,

sub_total DECIMAL(8,2) NOT NULL,

shipping_cost DECIMAL(8,2) NOT NULL,

total_cost DECIMAL(8,2) NOT NULL,

PRIMARY KEY(id);

This table is used to track basic sales information Although it lacks many of the columns you might find in a real-world implementation, the additional detail is omitted in an attempt to keep the focus on the concepts introduced in this chapter

Using Data Delimitation

Even if you’re a budding programmer, you’re probably already quite familiar with software’s exacting demands when it comes to data All i’s must be dotted and all t’s must be crossed; a single out-of-place character is enough to produce unexpected results Therefore, you can imagine the issues that might arise when attempting to convert data from one format to another Thankfully, a particularly convenient format-ting strategy has become commonplace: delimitation

Information structures like database tables and spreadsheets share a similar conceptual organization Each is broken down into rows and columns, each of which

is further broken down into cells Therefore, you can convert between formats as long

as you institute a set of rules for determining how the columns, rows, and cells are recognized An application utility will read in this data and, based on these rules, make the conversions necessary for adapting the data to its own formatting standards Typically, a character or a character sequence is used as a delimiter, separating each cell within a row, and each row from the following row For example, the sales table might be delimited in a format that separates each field by a comma and each row by

a newline character:

12309,45633,2007-12-19 01:13:42,22.04,5.67,27.71

12310,942,2007-12-19 01:15:12,11.50,3.40,14.90

Trang 5

12311,7879,2007-12-19 01:15:22,95.99,15.00,110.99

12312,55521,2007-12-19 01:30:45,10.75,3.00,13.75

Many data import and export utilities, including MySQL’s, revolve around the

concept of data delimitation

Importing Data

If you’ve invested the time to read this book, you likely are planning to make MySQL

a significant part of your application infrastructure Therefore, you’re probably already

thinking about how you’re going to migrate existing data, possibly from several sources,

into your new database environment In this section, you’ll learn about the two

built-in tools MySQL offers for importbuilt-ing delimited data sets built-into a table: LOAD DATA INFILE

and mysqlimport

Tip You might consider using the mysqlimport client in lieu of LOAD DATA INFILE when you need

to create batch imports executed from a cron job

Importing Data with LOAD DATA INFILE

The LOAD DATA INFILE statement, a command that is executed much like a query is

executed within the mysql client, is used to import delimited text files into a MySQL

table Its generalized syntax follows:

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'

[REPLACE | IGNORE]

INTO TABLE table_name

[CHARACTER SET charset_name]

[IGNORE number lines]

[SET column_name = expression, )]

Trang 6

Certainly one of MySQL’s longer query commands you’ve seen thus far, isn’t it? Yet it’s this wide array of options that makes this feature so powerful Each option is introduced next:

• LOW PRIORITY: This option forces execution of the command to be delayed until

no other clients are reading from the table

• CONCURRENT: Used in conjunction with a MyISAM table, this option allows other threads to retrieve data from the target table while the command is executing

• LOCAL: This option declares that the target infile must reside on the client side If omitted, the target infile must reside on the same server hosting the MySQL database When LOCAL is used, the path to the file can be either absolute or rela-tive according to the present location When omitted, the path can be absolute, local, or, if not present, assumed to reside in MySQL’s designated database directory or in the presently chosen database directory

• REPLACE: This option results in the replacement of existing rows with new rows possessing identical primary or unique keys

• IGNORE: Including this option has the opposite effect of REPLACE Read-in rows with primary or unique keys matching an existing table row will be ignored

• CHARACTER SET charset_name: MySQL will presume the input file contains

char-acters matching the character set assigned to the system variable character_set_database If the characters do not match this setting, use this option to iden-tify the file’s character set

• FIELDS TERMINATED BY 'character': This option signals how fields will be

termi-nated Therefore, TERMINATED BY ',' means that each field will end with a comma, like so:

12312,55521,2007-12-19 01:30:45,10.75,3.00,13.75The last field does not end in a comma because it isn’t necessary, as typically this option is used in conjunction with the LINES TERMINATED BY 'character' option Encountering the character specified by this other option by default also delimits the last field in the file, as well as signals to the command that a new line (row) is about to begin

Trang 7

• [OPTIONALLY] ENCLOSED BY 'character': This option signals that each field will

be enclosed by a particular character This does not eliminate the need for a

terminating character Revising the previous example, using the option FIELDS

TERMINATED BY ',' ENCLOSED BY '"' implies that each field is enclosed by a pair

of double quotes and delimited by a comma, like so:

"12312","55521","2007-12-19 01:30:45","10.75","3.00","13.75"

• The optional OPTIONALLY flag denotes that character strings only require

enclo-sure by the specified character pattern Fields containing only integers, floats,

and so on need not be enclosed

• ESCAPED BY 'character': If the character denoted by the ENCLOSED BY option

appears within any of the fields, it must be escaped to ensure that the field is not

incorrectly read in However, this escape character must be defined by ESCAPED

BY so that it can be recognized by the command For example, FIELDS TERMINATED BY

',' ENCLOSED BY ''' ESCAPED BY '\\' would allow the following fields to be

properly parsed:

'jason@example.com','Excellent product! I\'ll return soon!','2007-12-20'

• Note that because the backslash is treated by MySQL as a special character, you

need to escape any instance of it by prefixing it with another backslash in the

ESCAPED BY clause

• LINES: The following two options are pertinent to how lines are started and

terminated, respectively:

• STARTING BY 'character': This option defines the character intended to signal the

beginning of a line, and thus a new table row Use of this option is generally skipped in preference to the next option

• TERMINATED BY 'character': This option defines the character intended to signal

the conclusion of a line, and thus the end of a table row Although it could ably be anything, this character is most often the newline (\n) character In many Windows-based files, the newline character is often represented as \r\n

conceiv-• IGNORE number LINES: This option tells the command to ignore the first x lines

This is useful when the target file contains header information

Trang 8

• [(SET column_name = expression, )]: If the number of fields located in the

target file does not match the number of fields in the target table, you need to specify exactly which columns are to be filled in by the file data For example,

if the target file containing sales information consists of only four fields, id, client_id, order_time, and total_cost, rather than the six fields used in prior examples (id, client_id, order_time, sub_total, shipping_cost, and total_cost), yet in the target table all six fields remain, the command would have to be written like so:

LOAD DATA LOCAL INFILE "sales.txt"

INTO TABLE sales (id, client_id, order_time, total_cost);

Keep in mind that such attempts could fail should one or several of the missing columns be designated as NOT NULL in the table schema On such occasions, you need to either designate DEFAULT values for the missing columns or further manipulate the data file into an acceptable format

You can also set columns to variables such as the current timestamp For example, presume the sales table was modified to include an additional column named added_to_table:

LOAD DATA LOCAL INFILE "sales.txt"

INTO TABLE sales (id, client_id, order_time, total_cost)

SET added_to_table = CURRENT_TIMESTAMP;

■Tip If you would like the order of the fields located in the target file to be rearranged as they are read in for insertion into the table, you can do so by rearranging the order via the [(column_name, )] option

A Simple Data Import Example

This example is based upon the ongoing sales theme Suppose you want to import a file titled productreviews.txt, which contains the following information:

'43','jason@example.com','I love the new Website!'

'44','areader@example.com','Why don\'t you sell shoes?'

'45','anotherreader@example.com','The search engine works great!'

Trang 9

The target table, aptly titled productreviews, consists of three fields, and they are in the

same order (comment_id, email, comment) as the information found in productreviews.txt:

LOAD DATA LOCAL INFILE 'productreviews.txt' INTO TABLE productreviews FIELDS

TERMINATED BY ',' ENCLOSED BY '\'' ESCAPED BY '\\'

| 43 | jason@example.com | I love the new Website! |

| 44 | areader@example.com | Why don't you sell shoes? |

| 45 | anotherreader@example.com | The search engine works great! |

+ -+ -+ -+

Choosing the Target Database

You might have noticed that the preceding example referenced the target table but

did not clearly define the target database The reason is that LOAD DATA INFILE assumes

that the target table resides in the currently selected database Alternatively, you can

specify the target database by prefixing it with the database name, like so:

LOAD LOCAL DATA INFILE 'productreviews.txt' into table corporate.productreviews;

If you execute LOAD DATA INFILE before choosing a database, or without explicitly

specifying the database in the query syntax, an error will occur

Security and LOAD DATA INFILE

There are a few security issues that you should keep in mind regarding LOAD DATA INFILE:

• If LOCAL is not used (meaning the file will be read from the server side), the

executing user must possess the FILE privilege

• To disable LOAD DATA LOCAL INFILE, start the MySQL daemon with the

local-infile=0 option

Trang 10

Importing Data with mysqlimport

The mysqlimport client is really just a command-line version of the LOAD DATA INFILE SQL query Its general syntax follows:

mysqlimport [options] database textfile1 [textfile2 textfileN]

id, order_id, sub_total, shipping_cost, total_cost, and order_time:

45633,12309,22.04,5.67,27.71,2007-12-19 01:13:42942,12310,11.50,3.40,14.90,2007-12-19 01:15:127879,12311,95.99,15.00,110.99,2007-12-19 01:15:22

• Yet the sales table presented at the beginning of this chapter lists the fields in this order: id, client_id, order_time, sub_total, shipping_cost, and total_cost You can rearrange the input fields during the parsing process so that the data is inserted in the proper location, by including this option:

columns=id,order_id,sub_total,shipping_cost,total_cost,and order_time

• compress, -C: Including this option compresses the data flowing between the client and the server, assuming that both support compression This option is most effective if you’re loading a target file that does not reside on the same server as the database

• debug, -#: This option is used to create trace files when debugging

• delete, -d: This option deletes the target table’s contents before importing the target file’s data

Trang 11

• fields-terminated-by=, fields-enclosed-by=,

fields-optionally-enclosed-by=, fields-escaped-by=: These four options determine mysqlimport’s behavior

in terms of how both fields and lines are recognized during the parsing procedure

See the section “Importing Data with LOAD DATA INFILE,” earlier in this

chapter, for a complete introduction

• force, -f: Including this option causes mysqlimport to continue execution

even if errors occur during execution

• help, -?: Including this option generates a short help file and a comprehensive

list of the options discussed in this section

• host, -h: This option specifies the server location of the target database The

default is localhost

• ignore, -i: This option causes mysqlimport to ignore any rows located in the

target file that share the same primary or unique key as a row already located in

the table

• ignore-lines=n: This option tells mysqlimport to ignore the first n lines of the

target file It’s useful when the target file contains header information that

should be disregarded

• lines-terminated-by=: This option determines how mysqlimport will recognize

each separate line in the file See the section “Importing Data with LOAD DATA

INFILE,” earlier in this chapter, for a complete introduction

• lock-tables, -l: This option write-locks all tables located in the target

data-base for the duration of mysqlimport’s execution

• local, -L: This option specifies that the target file is located on the client By

default, it is assumed that this file is located on the database server; therefore,

you need to include this option if you’re executing this command remotely and

have not uploaded the file to the server

• low-priority: This option delays execution of mysqlimport until no other

clients are reading from the table

Trang 12

• password=your_password, -pyour_password: This option is used to specify the

password component of your authentication credentials If the your_password part of this option is omitted, you will be prompted for the password

• port, -P: If the target MySQL server is running on a nonstandard port (MySQL’s standard port is 3306), you need to specify that port value with this option

• replace, -r: This option causes mysqlimport to overwrite any rows located in the target file that share the same primary or unique key as a row already located in the table

• silent, -s: This option tells mysqlimport to output only error information

• socket, -S: This option should be included if a nondefault socket file had been declared when the MySQL server was started

• ssl: This option specifies that SSL should be used for the connection This would be used in conjunction with several other options that aren’t listed here See Chapter 29 for more information about SSL and the various options used to configure this feature

• user, -u: By default, mysqlimport compares the name/host combination of the executing system user to the mysql privilege tables, ensuring that the executing user possesses adequate permissions to carry out the requested operation Because it’s often useful to perform such procedures under the guise of another user, you can specify the “user” component of credentials with this option

• verbose, -v: This option causes mysqlimport to output a host of potentially useful information pertinent to its behavior

• version, -V: This option causes mysqlimport to output version information and exit

mysqlimport Data Import Examples

A simple demonstration of mysqlimport involves the update of inventory audit mation from the workstation of an accountant located in a company’s fiscal

infor-department to the database:

%>mysqlimport -h intranet.example.com -u fiscal -p replace \

-> compress local company inventory.txt

Trang 13

This command results in the compression and transmission of the data found in

the local text file (C:\audit\inventory.txt) to the table inventory located in the company

database Note that mysqlimport strips the extension from each text file and uses the

resulting name as the table into which to import the text file’s contents

Writing a mysqlimport Script

Some years ago, I was involved in the creation of a corporate Web site for a

pharma-ceutical corporation that, among other things, allowed buyers to browse descriptions

and pricing information for roughly 10,000 products This information was maintained

on a mainframe, and the data was synchronized on a regular basis to the MySQL

database residing on the Web server To accomplish this, a one-way trust was created

between the machines, along with two shell scripts The first script, located on the

main-frame, was responsible for dumping the data (in delimited format) from the mainframe

and then pushing this data file via sftp to the Web server The second script, located

on the Web server, was responsible for executing mysqlimport, loading this file to the

MySQL database This script was quite trivial to create, and looked like this:

#!/bin/sh

/usr/local/mysql/bin/mysqlimport delete silent \

fields-terminated-by='\t' lines-terminated-by='\n' \

products /ftp/uploads/products.txt

To keep the logic involved to a bare minimum, a complete dump of the entire

mainframe database was executed each night, and the entire MySQL table was deleted

before beginning the import This ensured that all new products were added, existing

product information was updated to reflect changes, and any products that were deleted

were removed To prevent the credentials from being passed in via the command line, a

system user named productupdate was created, and a my.cnf file was placed in the

user’s home directory, which looked like this:

[client]

host=localhost

user=productupdate

password=secret

The permissions and ownership on this file were changed, setting the owner to

mysql and allowing only the mysql user to read the file The final step involved adding

the necessary information to the productupdate user’s crontab, which executed the

script each night at 2 a.m The system ran flawlessly from the first day

Trang 14

Loading Table Data with PHP

For security reasons, ISPs often disallow the use of LOAD DATA INFILE, as well as many

of MySQL’s packaged clients like mysqlimport However, such limitations do not necessarily mean that you are out of luck when it comes to importing data, because you can mimic LOAD DATA INFILE and mysqlimport functionality using a PHP script The following script uses PHP’s file-handling functionality and a handy function known

as fgetcsv() to open and parse the delimited sales data found at the beginning of this chapter:

<?php

// Connect to the MySQL server and select the corporate database

$mysqli = new mysqli("localhost","someuser","secret","corporate");

// Open and parse the sales.csv file

// Insert the data into the sales table

$query = "INSERT INTO sales SET id='$id',

Trang 15

Keep in mind that execution of such a script might time out before completing the

insertion of a particularly large data set If you think that this might be the case, set PHP’s

max_execution_time configuration directive at the beginning of the script Alternatively,

consider using PHP or Perl or another solution to do the job from the command line

The next section switches directions of the data flow, explaining how to export

data from MySQL into other formats

Exporting Data

As your computing environment grows increasingly complex, you’ll probably need to

share your data among various disparate systems and applications Sometimes you

won’t be able to cull this information from a central source; rather, it must be constantly

retrieved from the database, prepped for conversion, and finally converted into a

format recognized by the target This section shows you how to easily export MySQL

data using the SQL statement SELECT INTO OUTFILE

Note Another commonly used data export tool, mysqldump, is introduced in Chapter 27 Although

officially it’s intended for data backup, it serves a secondary purpose as a great tool for creating data

export files

SELECT INTO OUTFILE

The SELECT INTO OUTFILE SQL statement is actually a variant of the SELECT query It’s

used when you want to direct query output to a text file This file can then be opened

by a spreadsheet application, or imported into another database like Microsoft Access,

Oracle, or any other software that supports delimitation Its general syntax format

follows:

SELECT [SELECT OPTIONS] INTO {OUTFILE | DUMPFILE} filename

EXPORT_OPTIONS

FROM TABLES [ADDITIONAL SELECT OPTIONS]

The following list summarizes the key options:

Trang 16

• OUTFILE: Selecting this option causes the query result to be output to the text file The formatting of the query result is dependent upon how the export options are set These options are introduced below.

• DUMPFILE: Selecting this option over OUTFILE results in the query results being written as a single line, omitting column or line terminations This is useful when exporting binary data such as a graphic or a Word file Keep in mind that you cannot choose OUTFILE when exporting a binary file, or the file will be corrupted Also, note that a DUMPFILE query must target a single row; combining output from two binary files doesn’t make any sense, and an error will be returned

if you attempt it Specifically, the error returned is, “Result consisted of more than one row.”

• EXPORT OPTIONS: The export options determine how the table fields and lines will

be delimited in the outfile Their syntax and rules match exactly those used in LOAD DATA INFILE, introduced earlier in this chapter Rather than repeat this information, please see the earlier section “Importing Data with LOAD DATA INFILE” for a complete dissertation

Usage Tips

There are several items worth noting regarding use of SELECT INTO OUTFILE:

• If a target file path is not specified, the directory of the present database is used

• The executing user must possess the selection privilege (SELECT_PRIV) for the target table(s)

• If a target file path is specified, the MySQL daemon owner must possess adequate privileges to write to the target directory

• The process leaves the target file world-readable and -writeable, an unexpected side effect Therefore, if you’re scripting the backup process, you’ll probably want

to change the file permissions programmatically once the query has completed

• The query will fail if the target text file already exists

• Export options cannot be included if the target text file is a dump file

Trang 17

A Simple Data Export Example

Suppose you want to export December, 2007 sales data to a tab-delimited text file,

consisting of lines delimited by newline characters:

SELECT * INTO OUTFILE "/backup/corporate/sales/1207.txt"

FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'

FROM corporate.sales

WHERE MONTH(order_time) = '12' AND YEAR(order_time) = '2007';

Assuming that the executing user has SELECT privileges for the sales table found

in the corporate database, and the MySQL daemon process owner can write to the

/backup/corporate/sales/ directory, the file 1207.txt will be created, with the following

data written to it:

12309 45633 2007-12-19 01:13:42 22.04 5.67 27.71

12310 942 2007-12-19 01:15:12 11.50 3.40 14.90

12311 7879 2007-12-19 01:15:22 95.99 15.00 110.99

12312 55521 2007-12-19 01:30:45 10.75 3.00 13.75

Note that the spacing found between each column does not consist of white space,

but rather is due to the tab (\t) character Also, at the conclusion of each line is the

invisible newline (\n) character

Exporting MySQL Data to Microsoft Excel

Of course, by itself, outputting data to a text file really doesn’t accomplish anything

except migrate it to a different format So how do you do something with the data?

For instance, suppose employees in the marketing department would like to draw a

parallel between a recent holiday sales campaign and a recent rise in sales To do so,

they require the sales data for the month of December To sift through the data, they’d

like it provided in Excel format Because Excel can convert delimited text files into

spreadsheet format, you execute the following query:

SELECT * INTO OUTFILE "/analysis/sales/1207.xls"

FIELDS TERMINATED BY '\t', LINES TERMINATED BY '\n' FROM corporate.sales

WHERE MONTH(order_time) = '7' YEAR(order_time) = '2007';

This file is then retrieved via a predefined folder located on the corporate intranet,

and opened in Microsoft Excel A window similar to Figure 38-1 will appear

Trang 18

If it isn’t already selected, choose the Delimited radio button, and click Next to proceed to the next window, the second step of the Text Import Wizard That window

is shown in Figure 38-2

Figure 38-1 Microsoft Excel’s Text Import Wizard

In the second step of the Text Import Wizard, choose the cell delimiter specified in the SELECT INTO OUTFILE statement Clicking Next takes you to the final screen, where you have the opportunity to convert any of the imported columns to one of Excel’s supported data formats; this task is not always necessary, but consider experimenting with the supported formats in case there is something more applicable for your particular situation Click Finish, and the data will open in normal Excel fashion

Trang 19

Figure 38-2 Choosing the delimiter in Excel

Summary

MySQL’s data import and export utilities offer powerful solutions for migrating data

to and from your MySQL database Using them effectively can mean the difference

between a maintenance nightmare and a triviality

This concludes the book Best of luck!

Trang 21

Index

Symbols and Numerics

$ metacharacter, Perl regular

expressions, 241

% wildcard, mysql client, 673

& character, htmlentities, 555

[], () metacharacters, Perl regular

expressions, 241 (period) metacharacter, Perl regular

expressions, 241

? option, mysqlxyz clients, 685

\ metacharacter, Perl regular

a, a+ file access modes, 288

a option, mysqlcheck client, 682

A parameter, date function, 326

a parameter, date function, 326, 329

A6 (IPv6 addresses) record type, DNS, 403

AAAA (IPv6 Address Record) record type,

DNS, 403about page, Zend Framework, 615

about.phtml view, Zend Framework, 616, 617

AboutController.php, Zend Framework,

613, 614absolute paths, identifying, 280

abstract classes, OOP, 193, 207–208abstract keyword, 180, 207

abstract methods, 180accented languages, 335character entity references, 255, 256access control, MySQL privileges, 735access privilege system, MySQL, 734–750access information storage, 738–750how it works, 735–737

accessibility, 505accessors, 172ACID acronym, 926actor parameterSoapClient constructor, 529SoapServer constructor, 533addAttachment methodMail_Mime package, PEAR, 418addElement method, HTML_QuickForm class, 356

addFunction method, SOAP, 533addition (+) operator, 90addition-assignment operator, 90addl_headers parameter, mail function, 412addl_params parameter, mail function, 412addslashes function, 43

addtl parameter, checkdnsrr function, 405AddType directive

installing Apache and PHP on Linux, 17installing Apache and PHP on

Windows, 19ad/ai/au prefixestrigger naming, MySQL, 856administrator, MySQL, 687, 688setting administrator password, 645, 646Adobe Dreamweaver CS3, 48

Trang 22

Adobe Flash

general PHP language features, 8

affected_rows method, mysqli, 782, 789

after triggers, MySQL, 851

before triggers compared, 852

naming conventions, 856

AGAINST function, MySQL

full text indexes, 914, 915

aggregate functions, SQLite, 589–590

alpha character class, 235

displaying special HTML characters, 257htmlentities function translating, 555AND (&&) operator, 92

AND (&) bitwise operator, 94AND (&) logical operator, 215ANY record type, DNS, 403, 405Apache

disabling broadcast of server signature, 39downloading, 12–13

downloading Apache manual, 14hiding configuration details, 546htaccess file, 29

httpd.conf file, 29installing on Linux, 15–17installing on Windows, 17–20reasons for installing, 11, 12ServerSignature directive, 546ServerTokens directive, 547viewing documentation, 14web site, 914

XAMPP as test environment, 12application directory

creating Zend Framework front-end controller, 612

application logicindex.tpl template, 478architecture

stored routines, 820ARCHIVE storage engine, MySQL, 703Archive_Tar package, PEAR, 310arg_separator.input directive, PHP, 40arg_separator.output directive, PHP, 40argc

register_argc_argv directive, 42arguments

see also parameters

default argument values, 118–119escapeshellarg function, 304escaping shell arguments, 554optional arguments, 118

Trang 23

passing arguments by reference, 117

passing arguments by value, 115–116

sizeof, 144sort, 147usort, 151–153array pointers, 129moving to first position, 141moving to last position, 141moving to next position, 140moving to previous position, 141array_chunk function, 162

array_combine function, 155array_count_values function, 144array_diff function, 159

array_diff_assoc function, 159array_flip array function, 258array_flip function, 146array_intersect function, 157array_intersect_assoc function, 158array_key_exists function, 136array_keys function, 137array_merge function, 153array_merge_recursive function, 154array_pop function, 136

array_push function, 135array_rand function, 160

Trang 24

$_FILES superglobal array, 390–391

adding and removing elements, 134–136

adding values in, 161

array pointers, 129

associative keys, 128

converting array into string, 262

counting array value frequencies, 144

determining unique array values, 145

dividing into smaller arrays, 162

extracting with list function, 131

moving array pointer, 140–141

multidimensional arrays, 129

numerical keys, 128

offset for numerically indexed arrays, 581

outputting, 133

passing array values to function, 142–143

printing for testing purposes, 133

random reordering of elements, 160

reading CSV file into, 292reading directory into, 300reading file into, 290register_long_arrays directive, 42removing and returning section of, 156removing duplicate values, 145retrieving array keys, 137retrieving array values, 138retrieving current array key, 139retrieving current array key and value, 140retrieving current array value, 139

retrieving last array value, 141retrieving next array value, 140retrieving previous array value, 141returning first element of, 135returning key/value pair at current pointer, 140

returning key/value pairs common to, 158returning key/value pairs in first array only, 159

returning last element of, 136returning number of values in, 143returning random keys from, 160returning section of, 155–157returning values common to, 157returning values in first array only, 159reversing key/value roles, 146

reversing order of elements, 146searching, 136–138

searching associative array keys, 136searching associative array values, 137searching for all matching elements, 242sorting, 145–153

by keys, 151case insensitive human sort order, 150element ordering options, 147key/value pairs not maintained, 147maintaining key/value pairs, 148natural human sort order, 150reverse (descending) order, 149sorting by ASCII value, 147sorting in another language, 145

Trang 25

arsort function, arrays, 149

AS keyword, MySQL, 869

ASCII attribute

CHAR datatype, MySQL, 712

asensitive cursors, MySQL, 903

asort function, arrays, 148

creating arrays with array function, 131

mapping arrays associatively, 128

returning key/value pairs common to

arrays, 158returning key/value pairs in first array

only, 159returning random keys from arrays, 160

returning result set as associative array,

576–577searching associative array keys, 136

searching associative array values, 137

associative keys, arrays, 128

associativity, operators, 88, 89

asXML method, SimpleXML, 524atime parameter, touch function, 302atomicity, database transactions, 926attachments

sending e-mail attachments, 418attributes

datatype attributes, MySQL, 714–718getting and setting attributes, PDO, 804stored procedures, MySQL, 826attributes method, SimpleXML, 523attributes parameter, ldap_search, 431attributes_only parameter, ldap_search, 431audit trails

reasons for using triggers, 850auditing

general language features, 10Auth package, PEAR, 319Auth_HTTP class, PEARauthenticating against MySQL database, 378–380

authentication methodologies, PHP, 377–380

installing, 377–378validating user credentials with Auth_HTTP, 378

authentication

see also privileges

access control stages, 735Auth_HTTP class, PEAR, 377–380connection authentication, 735database based authentication, 373–375file based authentication, 371–373general PHP language features, 8hard coded authentication, 370how privilege system works, 735HTTP authentication, 366–367

IP address based authentication, 375–377PHP authentication, 367–380

header function, 368isset function, 369tracing connection request, 737user login administration, 380–386

Trang 26

authentication variables, PHP, 367

determining if properly set, 369

authentication_dynamic table, MyISAM, 696

authentication_static table, MyISAM, 696

authenticationFile.txt, 371, 372

authns parameter, checkdnsrr function, 405

authorization

access control stages, 735

how privilege system works, 735

request authorization, 738

tracing connection request, 736

user table and, 738

auto login example, session handling,

459–461auto_append_file directive, PHP, 44

auto_detect_line_endings directive, PHP, 47

AUTO_INCREMENT datatype attribute,

MySQL, 714auto_prepend_file directive, PHP, 44

b file access mode, 288

b option, mysql client, 674

b type code, data types, 785

back_log parameter, MySQL, 655

backgroundshighlight.bg directive, PHP, 38backslash (\) character

escape sequences, PHP, 96inserting backslash delimiter before special characters, 244

MySQL using, 943backtick operator, 307backticks

executing shell command with, 307Bakken, Stig, 309

bandwidthcalculating network bandwidth, 423testing user bandwidth, 422–424base directory

open_basedir directive, PHP, 36

base exception class see exception class

baseclassclass inheritance, OOP, 199basename function, 278bd/bi/bu prefixestrigger naming, MySQL, 856before triggers, MySQL, 850after triggers compared, 852naming conventions, 856BEGIN command

conforming to SQL-99 syntax, 930BEGIN/END block, MySQL

LEAVE command, 836stored routines, 828, 829, 832beginTransaction method, PDO, 817BIGINT datatype, MySQL, 710bin directory

installing MySQL on Windows, 645bin2hex function, 562

binary data, SQLite, 585–587NULL character, 586sqlite_escape_string function, 586sqlite_udf_decode_binary function, 588sqlite_udf_encode_binary function, 588BINARY datatype attribute, MySQL, 714CHAR/VARCHAR datatypes, 712

Trang 27

binary distribution

installing MySQL on Linux, 639–640

binary output, returning, 307

bind_param method, mysqli, 784, 785, 787

bind_result method, mysqli, 784, 787

bindColumn method, PDO, 815

BLACKHOLE storage engine, MySQL, 704

BLOB datatype, MySQL, 713

blocks

embedding multiple code blocks, 59

BOOL (BOOLEAN) datatype, MySQL, 710

bracketed expressions, 239POSIX regular expressions, 233

predefined character ranges (character

classes), 234

break (<br>) tagconverting newline characters into, 254break statement, PHP, 107

switch statement, 101B-tree indexes, 700buffering

output_buffering directive, PHP, 32sqlite_unbuffered_query function, 575build method, PHP

Calendar package, PEAR, 344business logic

separating presentational logic from, 472

C

%c type specifier, 64

C option, mysql client, 673

C option, mysqlxyz clients, 685

CA (Certificate Authority) certificateREQUIRE X509 option, 761ssl-ca option, mysql client, 763ssl-capath option, mysql client, 763

CA issuersREQUIRE ISSUER option, 762cache directory

installing Smarty, 476cache_dir class membermodifying directory locations, 476cache_expire directive, session handling, 453cache_id parameter, display method, Smarty, 479

cache_lifetime attribute, Smarty, 498cache_limiter directive, session handling, 452

cachingcompilation compared, 497feeds, MagpieRSS, 519page caching, 497query caching, 624, 628setting for session-enabled pages, 452–453Smarty templating engine, 497–501creating multiple caches per template, 499

is_cached method, 499

Trang 28

caching attribute, Smarty, 497

caching templates, Smarty, 474

Cake Software Foundation, 605

CakeForge, 605

CakePHP framework, 605

calculate_bonus stored function, MySQL, 845

Calendar package, PEAR, 341–345

creating monthly calendar, 343–344

date and time classes, 342

decorator classes, 342

installing, 341

isValid method, 345

tabular date classes, 342

validating dates and times, 344

validation classes, 342

CALL statement, MySQL, 830

callback rule, HTML_QuickForm, 359

Canonical Name Record, DNS, 403

capability, stored routines, 821

capitalize function, Smarty, 480

carriage return

escape sequences, PHP, 96

CASCADE keyword, MySQL, 875

CASCADED CHECK OPTION option, MySQL

WITH CHECK OPTION clause, 871

case

manipulating case of characters in strings,

252–254case sensitivity

comparing two strings

case-insensitively, 250comparing two strings case-sensitively, 249

performing case-insensitive search, 236–237

performing case-sensitive search, 235–236

replacing text in case-insensitive

manner, 238replacing text in case-sensitive manner,

237–238splitting string based on case-insensitive

pattern, 239, 247splitting string based on case-sensitive

pattern, 238SQLite, 571

CASE statementstored routines, MySQL, 833case statement, PHP, 101case-insensitive searchPerl regular expression modifier, 240casting, PHP, 69–70

catching multiple exceptions, 226–229ceil function, MySQL, 895

certificatesREQUIRE SUBJECT option, 762ssl-cert option, mysql client, 763CHAR datatype, MySQL, 712character classes

POSIX regular expressions, 234–235character entity references, 255character sequences

range function, arrays, 133CHARACTER SET optionLOAD DATA INFILE statement, 942character sets

default_charset directive, PHP, 44installing MySQL on Windows, 645supported by htmlentities function, 256CHARACTER_SETS table, 725

characteristicsstored procedures, MySQL, 826characters

converting strings into bracketed expressions, 239

counting number in string, 271customized character conversion, 259htmlentities function, 555

ignoring newline characters, 295localized formats, 335

reading single character, 295reading specific number of, 293regular expressions, 232–248charset parameter, htmlentities function, 256

CHARSET placeholder, 596check option, myisamchk client, 682

Trang 29

working with multivalued form

components, 354checkdate function, PHP, 325

checkdnsrr function, 402–404

child class, OOP, 199

children method, SimpleXML, 524

chroot option, mysqld daemon, 734

ciphers

REQUIRE CIPHER option, 762

ssl-cipher option, mysql client, 763

class attribute

dns_get_record returning, 405

class constants, 176

class definition, 68

class inheritance, OOP, 199–201

child class (subclass), 199

constructors and inheritance, 201–203

see also objects, OOP

characteristics and behaviors, 166

checking if class exists, 189

class constants, 176

code conventions when creating, 167

generalized class creation syntax, 166

getting fields of class, 190

getting list of defined classes, 190

getting methods of class, 190

getting name of class, 189

getting parent class, 190static class members, 187–188clauses, MySQL

using with views, 868client-side cursors, MySQL, 903clone keyword, OOP, 195clone method, OOP, 196cloning, OOP, 194–197close method, mysqli, 771, 785, 787CLOSE statement, MySQL

cursors, 903, 906closedir function, 299closelog function, 218, 219closing files, 289

CNAME (Canonical Name Record) record type, DNS, 403

cntrl character class, 235code

see also PHP code

code reuse, 309getCode method, exception class, 224code editors, choosing, 48–50

coding consistency, PDO, 795COLLATION_CHARACTER_SET_APPLICABILITY table, 725

COLLATIONS table, 725Column_name column, columns_priv table, 749

Column_priv columncolumns_priv table, 749tables_priv table, 748COLUMN_PRIVILEGES table, 725columnCount method, PDO, 811column-names option, mysql, 673columns

granting column-level privileges, 756KEY_COLUMN_USAGE table, 726privilege verification process, 738retrieving first column in result set, 579retrieving number of columns in result set, 581

retrieving column types, 585

Trang 30

retrieving select result set columns, 578

revoking column-level privileges, 757

setting bound columns, PDO, 815–816

COLUMNS table, 725

columns_priv table

access control/authorization, 736

columns, table listing of, 749

MySQL access privilege system, 738, 749

columnset

use of term as placeholder, 748, 749

COM/DCOM support, PHP, 4

comma separated value (CSV) files, 292

command line, SQLite, 569–570

commands

escapeshellcmd function, 305, 554

executing shell commands, 301–302

executing system-level command, 305

retrieving system command results, 306

COMMENT characteristic

stored procedures, MySQL, 827

comments

configuration files, MySQL, 660

Smarty templating engine, 480

InnoDB tables example, 931, 932

commit method, mysqli, 790

commit method, PDO, 817

compare rulePEAR: HTML_QuickForm, 359comparison operators, 93performing comparisons with subqueries, 899

compatibilityzend.ze1_compatibility_mode directive, PHP, 31

Compatible Regular Expressions (PCRE) library, 4

compilationcaching compared, 497compile_dir class member, 476compile_id parameter, display method, Smarty, 479

Complete installationinstalling MySQL on Windows, 643compound datatypes, 67–68

compress optionmysqlimport utility, 946mysql client, 673, 685compressed MyISAM, 697compression, PHPzlib.output_compression directive, 33compression handler function, 33compression parameter, SoapClient, 529concatenate, 91

concatenation operators, 90, 91CONCURRENT option

LOAD DATA INFILE statement, 942conditional statements, MySQL, 832–834conditional statements, PHP, 98–101alternative syntax, 99

else statement, 99elseif statement, 100

if statement, 99switch statement, 101conditions

stored routines, MySQL, 844config_dir class member, 476config_load function, Smarty, 494

Trang 31

configuration directives see PHP

configuration directives

configuration directives, list of see PHP

configuration directives, list ofconfiguration parameters

track_vars, 82

configuration, MySQL, 652–660

automatically executing SQL

commands, 656configuration files summarized, 660

configuration templates, 658

configuring PHP for MySQL, 661

disabling DNS resolution, 657

limiting connections to local server, 657

logging potentially nonoptimal

queries, 656logging slow queries, 656

managing connection loads, 655

my.cnf configuration file, 657–660

MySQL Configuration Wizard, 643

mysqld_safe wrapper, 652

parameters, 653–657

reasons for MySQL popularity, 625

setting data directory location, 655

setting default storage engine, 655

setting maximum allowable simultaneous

connections, 656setting MySQL communication port, 657

setting MySQL daemon user, 657

viewing MySQL configuration

parameters, 653configuration, PHP, 540–545

changing document extension, 548

configuration parameters, 543–545

configuring PHP at build time on Linux, 26

configuring PHP for MySQL, 661

global variables, 493referencing configuration variables, 494sections, 493

configure command, PHP, 26connect method, mysqli class, 771

connection authentication see

authenticationconnection options, mysqlxyz clients, 684–685

connectionsback_log parameter, MySQL, 655closing, SQLite, 573

ldap_connect function, 427max_connections column, user table, 759max_connections parameter, MySQL, 656max_user_connections column, user table, 760

opening, SQLite, 571–573PDO (PHP Data Objects), 798–801embedding parameters into constructor, 799

handling connection errors, 801PDO connection-related options, 799placing parameters in file, 799referring to php.ini file, 799pinging server, 418

simultaneous connections for users, 736socket connections, establishing, 408–411sqlite_close function, 573

sqlite_open function, 571sqlite_popen function, 572tracing connection requests, 736–737connections, MySQL

managing connection loads, 655secure MySQL connections, 760–765connections, mysqli extension

closing, 771handling errors, 772securing connection information, 775

Trang 32

Console_Getopt package, PEAR, 310

running info command for, 317

invoking parent constructors, 184

invoking unrelated constructors, 186

613–615IndexController.php, 613

description, 446retrieving session name, 447retrieving information stored within, 84setcookie function, 84

setting session cookie lifetime, 451setting session cookie valid domain, 451setting session cookie valid URL path, 451–452

storing session information, 450use_cookies directive, 450Coordinated Universal Time (UTC), 324copyright symbol

character entity reference for, 255corporate_mysqli class, 889

count function, arrays, 143count_chars function, 271count_words function, 481CPAN (Comprehensive Perl Archive Network), 309

CrackLib extension, PHPavoiding easily guessable passwords, 381installation, 381

minimum password requirements, 381using, 382–383

using dictionaries, 383cracklib_dict.pwd dictionary, 383craigslist

prominent MySQL users, 631CREATE (SHOW CREATE) statement, MySQL, 843

create command, mysqladmin client, 676CREATE DATABASE statement, MySQL, 719CREATE privilege, 752

CREATE ROUTINE privilege, 752CREATE TABLE statement, MySQL, 720copying tables, 722

IF NOT EXISTS clause, 721TEMPORARY keyword, 722CREATE TEMPORARY TABLES privilege, 752

Trang 33

CREATE TRIGGER statement, MySQL, 854

trigger naming conventions, 856

CREATE USER privilege, 752

CREATE USER statement, MySQL, 750

CREATE VIEW privilege, 752

CREATE VIEW statement, MySQL, 865

crontab

using mysql in batch mode, 668

cross-site scripting, 551

cryptType element

Auth_HTTP class, PEAR, 380

CSS (Cascading Style Sheets)

clash of syntax between Smarty and, 495

embedding into Smarty template, 492

literal tag, Smarty, 492

Smarty configuration files and, 494

tweaking table styles with CSS and

HTML_Table, 884using with Smarty templating engine,

495–497

CSV filescommon usage of, 292reading CSV file into array, 292CSV storage engine, MySQL, 703curly brackets {}

clash of syntax between Smarty and CSS, 495

currencycharacter entity references, 255localized formats, 335

current function, arrays, 139current_user function, 759currentpage variable, MySQL, 896cursor_offset parameter

fetch method, PDO, 812cursor_orientation parameterfetch method, PDO, 812cursors, MySQL, 902–906asensitive cursors, 903client-side cursors, 903closing, 906

creating, 904forward-only cursors, 903insensitive cursors, 903introduction, 879, 903opening, 904

read-only cursors, 903server-side cursors, 903using, 904

using with PHP, 906Custom installationinstalling MySQL on Windows, 643custom session handlers, 462–469

D

%d type specifier, 64

\D, \d metacharacters, Perl regular expressions, 241

D option, mysql client, 673

D, d parameters, date function, 326

D parameter, numeric datatypesdigits following decimal point, 710

Trang 34

d type code, data types, 785

outputting data to web browser, 61–65

poorly protected data, 539

sales table, 940

sanitizing user input, 550–558

PEAR: Validate package, 556–558

data delimitation, 940

data encryption see encryption

data handling

deleting LDAP data, 438–439

inserting LDAP data, 436–437

updating LDAP data, 438

data handling category

PHP configuration directives, 40–45

data management, MySQL, 622

data mining, MySQL, 624

data retrieval, PDO, 811–815

database abstraction layers, 793

PDO (PHP Data Objects), 795–817

database abstraction solutionsgeneral PHP language features, 9database based authentication, PHP, 373–375

authenticating user against MySQL database, 374

authenticating using login pair and IP address, 376

database configurationinstalling MySQL on Windows, 644

database connections see connections

database option, mysql client, 673

database security see security

database supportgeneral PHP language features, 9PDO (PHP Data Objects), 797

database transactions see transactions

database versions offered by web host, 52databases

applications accessing, 793changing table structure, 724copying tables, 722

creating, 719creating SQLite database, 571creating tables, 720

creating tables conditionally, 721creating temporary tables, 722deleting, 720

deleting tables, 724designating as default, 719indexes, 907–919

migrating between, 311MySQL access privilege system, 738MySQL storage engines, 693–706selecting database, mysqli extension, 771transactions, 925–937

using multiple storage engines, 706viewing, 718

viewing tables, 722, 723datadir option, MySQL, 655datadir parameter, MySQL, 655

Trang 35

datatype attributes, MySQL, 714–718

Boolean, 65compound datatypes, 67–68converting between datatypes, 69–70float, 66

functions for determining variable type, 72

functions for verifying and converting, 71gettype function, 71

integer, 65is_name function, 72object, 68

scalar datatypes, 65settype function, 71string, 66

type casting, 69–70type identifier functions, 72type juggling, 70–71type related functions, 71date and time datatypes, MySQL, 707invalid value inserted into, 708nonalphanumeric delimiters, 707date and time functions, PHP, 324calculating dates, 340

checkdate function, 325date function, 325–329determining days in current month, 339displaying localized date and time, 334–338

displaying web page modification date, 338

getdate function, 330–331getlastmod function, 338gettimeofday function, 329mktime function, 332–333

Trang 36

Calendar package, PEAR, 342

DATE datatype, MySQL, 707

outputting current time, 329

outputting standard date, 327

outputting verbose date, 328

Calendar package, PEAR, 341–345

dates prior to Unix epoch, 324

determining days in current month, 339

displaying localized date and time,

334–338displaying web page modification

date, 338formatting dates and times, 325–330

formatting dates, Smarty, 481

localized formats, 335

localizing, 598–600

object-oriented enhancements, 345–348

standardized format for, 323

US and European formats, 598

Db columncolumns_priv table, 749

db table, 745host table, 746procs_priv table, 749tables_priv table, 748

DB package, PEAR, 311

db tableaccess control/authorization, 736columns, table listing of, 745MySQL access privilege system, 738, 745User/Db match, 745

User/Host/Db triplet, 745DB_Table, 606

dblogin arrayAuth_HTTP class, PEAR, 379DDL statements

MySQL rollbacks, 933deb packages

installing MySQL on Linux, 637debug option, mysqlimport utility, 946debugging, mysqli, 768

DECIMAL datatype, MySQL, 711Decision Support (DSS)

installing MySQL on Windows, 644DECLARE statement, MySQL

cursors, 903, 904stored routines, 828declaring variables, PHP, 74decode_binary parametersqlite_column function, 578sqlite_fetch_array function, 576decoding

session_decode function, 457sqlite_udf_decode_binary function, 588decorator classes

Calendar package, PEAR, 342

Trang 37

decrement ( ) operator, 91

dedicated server hosting, 50

default argument values, 118–119

DEFAULT datatype attribute, MySQL, 714

default directory

creating Zend Framework front-end

controller, 612default function, Smarty, 482

highlight.default directive, PHP, 38

defaults-extra-file option, mysqlxyz clients,

658, 685defaults-file option, mysqlxyz clients, 685

default-storage-engine parameter,

MySQL, 655default-table-type parameter, MySQL, 655

define function, 86

define_syslog_variables function, 218

DEFINER clause/setting, MySQL

CREATE TRIGGER statement, 854

modifying stored routines, 841

SQL SECURITY characteristic, 827

stored routines, 825

views, 871

DELETE command, mysqli extension, 777

delete option, mysqlimport utility, 946

delimiter syntax

asp_tags directive, PHP, 31

delimiterschanging Smarty default delimiters, 496choosing in Excel, 955

creating design template, 477templating engines, 472, 473delimiting data

importing and exporting data, 940delimiting PHP code, 56–58

ASP-style syntax, 58default delimiter syntax, 56embedding multiple code blocks, 59script tag, 58

short tags, 57deref parameter, ldap_search function, 432DESCRIBE statement, MySQL, 723

using mysql in interactive mode, 666viewing view definition, 872

views, 866destroying variables, 8destruct function, 186destructors, OOP, 186–187Detailed ConfigurationMySQL Configuration Wizard, 644, 645DETERMINISTIC characteristic, MySQL, 827dictionaries

CrackLib extension using, 383digit character class, 235digital signaturesencrypting data with md5 function, 559

directives, PHP see PHP configuration

directivesdirectories

see also LDAP

closing directory stream, 299datadir option, MySQL, 655extension_dir directive, 46open_basedir directive, 36, 545opening directory stream, 299parsing directory contents, 299reading directory contents, 299, 301reading directory into array, 300

Trang 38

removing, 301

retrieving directory from path, 279

retrieving directory size, 283

returning elements of, 299

determining used space on disk

partition, 282display method, HTML_QuickForm

class, 356display method, Smarty, 479

converting DN to readable format, 440

LDAP working with, 440–441

ldap_dn2ufn function, 440

ldap_explode_dn function, 440

loading DN into array, 440–441

retrieving LDAP data, 432

DNS (Domain Name System), 407checking for existence of DNS records, 402–404

DNS_ prefix for dns_get_record function,

404, 405record types, 403, 405retrieving DNS resource records, 404–406retrieving MX records, 407

verifying existence of domain, 404verifying whether domain name is taken, 403

DNS functions, PHPcheckdnsrr function, 402–404dns_get_record function, 404–406getmxrr function, 407

DNS resolutionskip-name-resolve parameter, MySQL, 657

DNS_ALL record type, 405DNS_ANY record type, 405dns_get_record function, 404–406DNS_HINFO record type, 405DNS_NS record type, 405

DO WHILE statementMySQL equivalent, 838

do while statement, PHP, 103doc_root directive, PHP, 46, 544DocBlocks, phpDocumentor, 60document extension

configuring PHP securely, 548documentation, Apache, 14documentation, PHP, 14, 15DocumentRoot directive, Apache, 549documents

recently viewed documents, 461Dollar sign

escape sequences, PHP, 96DOM (Document Object Model)loading XML from DOM document, 522domain name servers, 402

Domain Name System see DNS

Trang 39

double datatype see float datatype

DOUBLE datatype, MySQL, 711

determining available PDO drivers, 798

drop command, mysqladmin client, 676

DROP DATABASE command, MySQL, 720

DROP privilege, MySQL, 752

DROP PROCEDURE, MySQL, 832

DROP statement, MySQL, 841

DROP TABLE statement, MySQL, 724

DROP TRIGGER statement, MySQL, 859

DROP USER statement, MySQL, 751

DROP VIEW statement, MySQL, 875

Drop_priv column

db table, 745

host table, 747

user table, 739, 742

DSN (Data Source Name)

Auth_HTTP class, PEAR, 379

DSN parameter

connecting to database server, PDO, 798

dsttime value, gettimeofday function, 329

du command, 283

DUMPFILE optionSELECT INTO OUTFILE statement, 952durability

database transactions, 926dynamic extensions categoryPHP configuration directives, 48dynamic MyISAM, 697

E

E, e options, mysql client, 676E_ALL error level, 214E_STRICT error level, 215each function, arrays, 140echo statement, PHP, 62Eclipse framework, 49editors

choosing code editor, 48–50ELSE statement, MySQL, 833else statement, PHP, 99else/elseif clauses, Smarty, 485ELSEIF statement, MySQL, 833elseif statement, PHP, 100e-mail, 418

see also mail function

Invalid_Email_Exception class, 226, 229Mail package, PEAR, 311

sending attachments, 418sending e-mail using PHP script, 412–418sending e-mail with multiple

recipients, 414sending HTML formatted e-mail, 415–417sending plain text e-mail, 413

verifying e-mail address exists, 404e-mail addresses

validating with PEAR: Validate, 558email rule

PEAR: HTML_QuickForm, 359embedded MySQL serverMySQL 4, 629

mysqli, 768

Trang 40

embedding PHP code in web pages, 56–59

ASP-style syntax, 58

default delimiter syntax, 56

embedding multiple code blocks, 59

script tag, 58

short tags, 57

employee bonus interface

integrating routines into web

applications, 845enable_dl directive, PHP, 46

Auth_HTTP class, PEAR, 380

determining message integrity and

authenticity, 562effect on performance using SSL, 765

encrypting data with md5 function, 559

ensuring traffic is encrypted, 765

end function, arrays, 141

end of file (EOF)

identifying if EOF reached, 287

recognizing end of file character, 287

end-of-line (EOL) characterauto_detect_line_endings directive, PHP, 47

engine directive, PHP, 30ENGINES table, 725ENT_XYZ valuesquote_style parameter, htmlentities function, 255

Enterprise Application Integration (EAI), 505enterprise-level SQL features, 623

ENUM datatype, MySQL, 713NULL attribute, 713placeholders for enum, 823, 824

$_ENV superglobal variable, 85environment variables, PHPsafe_mode_allowed_env_vars directive,

36, 543safe_mode_protected_env_vars directive,

36, 543EOF (end of file), 287equality operators, 93ereg function, 235–236ereg_replace function, 237–238eregi function, 236–237eregi_replace function, 238errno method, mysqli, 772, 789error atribute, $_FILES superglobal, 85error code parameter, exception class constructor, 224

error handling

see also exception handling

configuration directives, 213, 214–217displaying errors to browser, 215–216displaying startup errors, 216error messages in syslog, 217error messages in text file, 218identifying log file, 216ignoring errors originating from same location, 217

ignoring repeated errors, 217ldap_err2str function, 441ldap_errno function, 442

Ngày đăng: 09/08/2014, 14:21

TỪ KHÓA LIÊN QUAN