did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780131875081

PHP and MySQL by Example

by ;
  • ISBN13:

    9780131875081

  • ISBN10:

    0131875086

  • Edition: 1st
  • Format: Paperback
  • Copyright: 2006-11-22
  • Publisher: Prentice Hall
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $54.99 Save up to $9.10
  • Digital
    $45.89
    Add to Cart

    DURATION
    PRICE

Supplemental Materials

What is included with this book?

Summary

A gentle introduction to building dynamic, database-driven websites for designers with no previous programming experience.

Author Biography

Ellie Quigley has taught scripting languages in Silicon Valley for more than twenty years. Her Perl and shell programming classes at the University of Santa Cruz Extension program have become part of Silicon Valley lore. Her best-selling books include UNIX ® Shells by Example, Fourth Edition; Perl by Example, Third Edition; and Javascript by Example, all from Prentice Hall.


Marko Gargenta has worked as an e-commerce consultant and instructor since 1996. He has created the Marakana Ecommerce Seminar Series, consulted with Sun Microsystems Educational Services, and designed and delivered PHP and MySQL courses for OpNet Community Ventures and AcademyX. For more on Marko’s training company go to http://marakana.com.

Table of Contents

Preface xxiii
Acknowledgments xxiv
Introduction
1(12)
From Static to Dynamic Web Sites
1(3)
Static Web Sites
1(1)
Dynamic Web Sites
2(1)
What Is Open Source?
3(1)
About PHP
4(3)
Where to Get PHP and Documentation
5(2)
About MySQL
7(4)
Where to Get MySQL and Documentation
7(1)
Features of MySQL
7(2)
How to Install MySQL and PHP
9(1)
Advantages of MySQL and PHP
9(1)
High Performance
9(1)
Built-In Libraries
10(1)
Extensibility
10(1)
Relatively Low Cost
10(1)
Portability
10(1)
Developer Community
10(1)
Ease of Learning
10(1)
Chapter Summary
11(2)
What You Should Know
11(1)
What's Next?
11(2)
Getting Started
13(28)
The Life Cycle of a Web Page
13(2)
Analysis of a Web Page
14(1)
The Players
14(1)
The Steps
14(1)
The Anatomy of a PHP Script
15(6)
The Steps of Writing a PHP Script
15(1)
Finding a Text Editor
15(1)
Naming the PHP File---The .php Extension
16(1)
PHP Tags
16(1)
Additional PHP Tags
17(1)
Where to Save the Script
18(1)
The Script Content
18(1)
Quoting in Strings
19(1)
Printing Strings
20(1)
Executing the Script
20(1)
Some Things to Consider
21(10)
PHP and HTML Are Different Languages
21(2)
Statements, Whitespace, and Line Breaks
23(2)
Comments
25(2)
Using PHP Functions
27(4)
Review
31(6)
PHP on the Command Line
32(1)
Finding the Version of PHP
32(1)
Script Execution at the Command Line
32(2)
Running PHP Interactively
34(1)
PHP Command-Line Options
34(1)
The php.ini File
35(2)
Chapter Summary
37(4)
What You Should Know
37(1)
What's Next?
38(1)
Lab
38(3)
PHP Quick Start
41(18)
Quick Start, Quick Reference
41(16)
A Note to Programmers
41(1)
A Note to Nonprogrammers
41(1)
PHP Syntax and Constructs
42(15)
Chapter Summary
57(2)
What's Next?
57(2)
The Building Blocks: Data Types, Literals, Variables, and Constants
59(48)
Data Types
59(11)
Numeric Literals
60(2)
String Literals and Quoting
62(2)
The Here Document---A Special Kind of Quoting
64(2)
Escape Sequences
66(2)
Boolean Literals
68(1)
Special Data Types
68(1)
Null
68(1)
Resource
68(1)
The gettype() Function
69(1)
Variables
70(29)
Definition and Assignment
70(1)
Valid Names
71(1)
Declaring and Initializing Variables
71(1)
Double, Single, and Backquotes in Assignment Statements
72(3)
Displaying Variables
75(1)
The print and echo Constructs
75(1)
Shortcut Tags
76(2)
Variables and Mixed Data Types
78(1)
Type Casting
79(1)
Concatenation and Variables
79(1)
References
80(2)
Variable Variables (Dynamic Variables)
82(2)
Scope of Variables
84(1)
Local Variables
84(1)
Global and Environment Variables
84(1)
Managing Variables
85(1)
The isset() Function
85(3)
The empty() Function
88(1)
The unset() Function
89(1)
Introduction to Form Variables
90(1)
The php.ini File and register_globals
90(1)
How PHP Handles Form Input
91(4)
Extracting the Data by Request
95(3)
Predefined Variables
98(1)
Constants
99(5)
What Is a Constant?
99(1)
Creating Constants with the define() Function
100(2)
The constant() Function
102(1)
Predefined and ``Magic'' Constants
102(2)
Chapter Summary
104(3)
What You Should Know
104(1)
What's Next?
105(1)
Lab
105(2)
Operators
107(42)
About PHP Operators and Expressions
107(38)
Assignment
108(1)
Precedence and Associativity
108(4)
Arithmetic Operators
112(1)
Short Circuit Assignment Operators
113(2)
Autoincrement and Autodecrement Operators
115(1)
The Autoincrement/Autodecrement and Assignment
115(2)
Some Useful Math Functions
117(1)
Casting Operators
118(2)
Concatention Operator
120(2)
Comparison Operators
122(1)
What Is Equal?
122(1)
What Is Identical?
123(1)
Comparing Numbers
124(1)
Comparing Strings
125(1)
Logical Operators
126(1)
The && (and) Operator, the Logical AND
127(3)
The || (or) Operator
130(2)
The Difference Between &&/|| and the Words and/or
132(2)
The Logical XOR Operator
134(1)
The ! Operator
135(3)
The Conditional Operator
138(2)
Bitwise Operators
140(1)
A Little Bit About Bits
140(1)
Using Bitwise Operators
140(1)
Bitwise Shift Operators
141(2)
Execution Operators
143(1)
Error Control Operator
143(1)
Adding the @ Operator
144(1)
Type Operators
145(1)
Chapter Summary
145(4)
What You Should Know
145(1)
What's Next?
146(1)
Lab
146(3)
Strings
149(72)
What Is a String?
149(6)
Quotes
150(1)
Single Quotes
150(1)
Quoting Errors
151(1)
Double Quotes
152(1)
String Operators
152(1)
Concatenation
152(2)
Equal and Identical
154(1)
String Functions
155(59)
Formatting and Printing Strings
155(1)
The printf() Function
156(3)
The sprintf() Function
159(1)
The fprintf() Function
160(1)
Formatting Numbers and Money
160(1)
The number_format() Function
161(1)
The money_format() Function
162(1)
Finding the Length of a String
163(1)
The strlen() Function
163(1)
Finding the Number of Words in a String
164(1)
The str_word_count() Function
164(1)
Changing the Case of Strings
164(1)
The strtoupper() and strtolower() Functions
165(1)
The ucfirst() and ucwords() Functions
165(1)
The mb_convert_case() Function
166(1)
Comparing Strings
167(1)
The strcmp() Function (Case Sensitive)
168(2)
The strcasecmp() Function (Case Insensitive)
170(1)
The strncasecmp() Function (Limits Character Length)
171(1)
The strnatcmp() Function (Natural Order Comparison)
172(1)
The strspn() Function (Using a Mask for Comparison)
173(1)
The strcspn() Function (Comparison Not Matching a Mask)
174(1)
Finding Similarities in Strings
174(1)
The soundex() and metaphone() Functions (Phonic Similarity)
174(2)
The similar_text() and levenshtein() Functions (Textual Similarity)
176(3)
Splitting a String
179(1)
The strtok() Function
179(2)
Repeating a String
181(1)
Trimming and Padding Strings
181(1)
The trim() Functions---trim(), ltrim(), chop(), rtrim()
182(2)
The str_pad() Function
184(1)
Search and Replace
185(1)
The str_replace() and stri_replace() Functions
186(3)
Finding a Position in a String
189(1)
The strpos() Function
189(2)
The strrpos() and strripos() Functions
191(1)
Extracting Pieces of a String---Substrings
191(1)
The strchr(), strrchr(), and strichr() Functions
192(1)
The substr() Function
193(3)
The substr_replace() Function
196(2)
The substr_count() Function
198(2)
Special Characters and Strings
200(1)
Individual Characters and the Curly Brace Syntax
200(1)
Line Breaks with the nl2br() and wordwrap() Functions
200(5)
ASCII Character Values and the chr() Function
205(1)
ASCII Character Values and the ord() Function
206(1)
Transposing Characters and the strstr() Function
206(1)
Slashes and the addslashes() and addcslashes() Functions
206(2)
Slashes and the stripslashes() Function
208(2)
Working with HTML Special Characters
210(1)
The htmlspecialchars() Function
211(2)
The htmlentities() Function
213(1)
Other String Functions
214(4)
Chapter Summary
218(3)
What You Should Know
218(1)
What's Next?
219(1)
Lab
219(2)
Conditionals and Loops
221(26)
Control Structures, Blocks, and Compound Statements
221(11)
Conditionals
222(1)
if/else
222(3)
if/elseif
225(3)
The switch Statement
228(4)
Loops
232(11)
The while Loop
232(2)
The do/while Loop
234(1)
The for Loop
235(1)
The for Loop and Repetitive Form Fields
236(3)
The foreach Loop
239(1)
Loop Control with break and continue
239(2)
Nested Loops
241(2)
Chapter Summary
243(4)
What You Should Know
243(1)
What's Next?
244(1)
Lab
244(3)
Arrays
247(90)
What Is an Array?
247(63)
Creating and Naming an Array
251(1)
The array() Function
252(1)
The Array Identifier []
252(1)
The range() Function
253(2)
The array_fill() Function
255(2)
Accessing an Array's Elements (Values)
257(1)
Elements of a Numeric Array
257(2)
Elements of an Associative Array
259(1)
Watch Those Quotes!
260(1)
Mixing Elements in an Array
260(2)
Printing an Array
262(1)
The print_r() Function
262(3)
The var_dump() Function
265(1)
Using Loops to Access Array Elements
266(1)
The for Loop
266(1)
The while Loop
267(3)
The foreach Loop
270(2)
Modifying a Value by Reference with a foreach Loop
272(2)
Checking If an Array Exists
274(1)
Creating Strings from Arrays and Arrays from Strings
275(1)
The implode() Function
276(1)
The explode() Function
276(2)
Finding the Size of an Array
278(1)
The count() and sizeof() Functions
278(1)
The array_count_values() Function
279(2)
Extracting Keys and Values from Arrays
281(1)
The array_keys() Function
281(2)
The array_values() Function
283(1)
The each() Function
284(2)
Creating Variables from Array Elements
286(1)
The list() Function and Numeric Arrays
286(2)
The extract() Function and Associative Arrays
288(5)
Multidimensional Arrays
293(3)
Finding the Size of a Mutidimensional Array
296(2)
Sorting Arrays
298(1)
Alphabetic Sort of Numerically Indexed Arrays
298(1)
Alphabetic Sort
299(1)
Numeric Sort
300(2)
Reversed Sort
302(1)
Sort an Associative Array by Values
302(1)
Sort by Value in Reverse Order
303(2)
Sort an Associative Array by Key
305(1)
Randomizing an Array
306(1)
Randomizing the Keys
306(3)
Shuffling a Numeric Array (Randomizing the Values)
309(1)
Modifying Arrays (Unsetting, Deleting, Adding, and Changing Elements)
310(25)
Removing an Array and Its Elements
310(1)
Removing an Entire Array
311(1)
Removing the Last Element of an Array
311(2)
Removing the First Element of an Array
313(1)
Removing Duplicate Values from an Array
314(1)
Adding Elements to an Array
315(1)
Adding Elements to the Beginning of an Array
315(2)
Adding Elements to the End of an Array
317(1)
Splicing an Array---Removing and Adding Elements
318(2)
Copying Elements of an Array
320(1)
The array_slice() Function
320(2)
Combining and Merging Arrays
322(1)
The array_combine() Function
322(1)
The array_merge() Function
323(1)
Merging Numerically Indexed Arrays
323(2)
Merging Associative Arrays
325(1)
The array_merge_recursive() Function
326(1)
Array Operators
327(1)
The Union Operator
327(2)
The Equality and Identical Operators
329(1)
More Array Functions
330(5)
Chapter Summary
335(2)
What You Should Know
335(1)
What's Next?
336(1)
Lab
336(1)
User-Defined Functions
337(42)
What Is a Function?
337(39)
Function Declaration, Definition, and Invocation
338(1)
Where to Put Functions
338(1)
How to Define a Function
338(1)
How to Call a Function
339(2)
Passing Arguments
341(1)
What Are Arguments and Parameters?
341(1)
Passing by Value
342(2)
Missing Arguments
344(1)
Variable Number of Arguments
345(2)
Setting Default Parameters
347(2)
Passing by Reference
349(2)
Dynamic Function Calls
351(1)
Return Values
351(1)
Returning a Single Value
352(1)
Conditional Returns
353(2)
Returning Multiple Values
355(3)
Using Callback Functions
358(1)
The array_map() Function
359(1)
The array_walk_recursive() Function
360(2)
Scope
362(1)
Local Scope
362(1)
Global Scope
363(2)
The $Globals[]Array
365(1)
Static Variables
365(3)
Nesting Functions
368(2)
Recursive Functions
370(3)
Function Libraries---Requiring and Including
373(1)
The require() and include() Constructs
373(3)
Chapter Summary
376(3)
What You Should Know
376(1)
What's Next?
377(1)
Lab
377(2)
More on PHP Forms
379(62)
Introduction
379(1)
Review of HTML Forms
379(11)
The Browser's Role
380(1)
The GET Method
381(1)
The POST Method
382(1)
The Server's Role
383(1)
Creating HTML Forms
384(1)
The Steps to Produce a Form
385(4)
The method Attribute
389(1)
The action Attribute
389(1)
PHP and Forms
390(48)
The register_globals Directive
391(1)
PHP Superglobals for Retrieving Form Data
392(1)
The Request Method
393(1)
Strange Characters in Form Field Names and User Input
393(1)
Dots and Spaces in HTML Input Device Names
393(2)
Stripping out Slashes
395(1)
Form Parameters the $_Request Array
396(2)
Using the extract() Function
398(2)
Form Parameters and the Medium Style
400(1)
The $_Get Array
400(2)
Security
402(1)
The $_POST Array
403(3)
Form Parameters and the Long (Old) Style
406(1)
Processing Forms with Multiple Selections
406(1)
Creating the Form with Select and Check Boxes
406(2)
Processing the Form with Multiple Selections
408(2)
Forms Using an Image Button
410(3)
Self-Processing HTML Forms
413(1)
Checking If the Form Was Submitted
413(2)
Using Hidden Fields
415(2)
Redirecting the User
417(1)
The Location Header
417(1)
Using the Correct URi for Redirection
418(3)
Uploading Files
421(1)
Attributes for the <Form> Tag and the file Type
421(1)
PHP's $_Files Array
422(3)
Moving the Uploaded File
425(2)
Sticky Forms
427(4)
Where to Get Information About Superglobal Arrays
431(1)
The phpinfo() Function
431(1)
How to Get Server Information
432(5)
How to Get Information About the Environment
437(1)
Chapter Summary
438(3)
What You Should Know
438(1)
What's Next?
439(1)
Lab
439(2)
Files and Directories
441(56)
Files
441(5)
File Permissions and Ownership
441(1)
UNIX/Linux Permissions
441(1)
Ownership and Groups
441(1)
Permissions
442(1)
Changing Permissions at the Command Line
442(2)
Windows Permissions
444(2)
The Web Server, PHP, and Permissions
446(37)
PHP Built-In Functions
447(1)
The chown() Function
447(1)
The chgrp() Function
447(1)
The chmod() Function
447(1)
The Filehandle
448(1)
Opening a File
448(1)
The fopen() Function
448(1)
The Mode and Permissions
449(2)
Opening a File for Reading
451(1)
The fgets() Function---Reading Lines from a File
451(2)
The fgetss() Function---Stripping HTML Tags from a File
453(2)
The fgetc() Function---Reading Characters from a File
455(1)
The fread() Function---Reading Chunks from a File
456(2)
Positioning the File Pointer
458(1)
The fseek() Function
459(1)
The rewind() Function
459(2)
The ftell() Function---Finding the Current Position in a File
461(2)
Opening a URL for Reading
463(1)
Reading from Files Without a Filehandle
464(1)
The file_get_contents() Function---Reading the Whole File into a String
464(1)
The file() Function---Reading the Whole File into an Array
465(1)
Using explode() and implode()
466(4)
The readfile() Function---Reading and Writing a File
470(1)
Opening a File for Writing and Appending
471(1)
The fwrite() and fputs() Functions
472(1)
The file_put_contents() Function
472(1)
Appending to a File
473(1)
Locking Files with flock()
474(1)
File Checks
475(1)
The file_exists() Function
476(1)
The is_file() Function
477(1)
The is_readable() Function
478(1)
The is_writable() Function
479(2)
Creating, Copying, Renaming, and Deleting Files
481(1)
The copy() Function---Making a Copy of a File
481(1)
The rename() Function---Renaming and/or Moving a File
482(1)
The unlink() Function---Removing a File
482(1)
Directories
483(4)
Opening and Reading from a Directory
483(1)
The opendir() Function
483(1)
The readdir() Function
484(1)
Getting Path Information
485(1)
Changing and Getting the Current Directory
486(1)
Managing Content with Include Files
487(7)
A Real-World Example
488(6)
Chapter Summary
494(3)
What You Should Know
494(1)
What's Next?
495(2)
Regular Expressions and Pattern Matching
497(70)
What Is a Regular Expression?
497(2)
Pattern-Matching Functions
499(66)
Finding a Pattern
500(1)
The preg_match() Function
500(3)
The preg_match_all() Function
503(2)
Pattern-Matching Modifiers
505(1)
Searching and Replacing
506(1)
The preg_replace() Function
506(3)
Evaluating the Replacement Side with the e Modifier
509(1)
The preg_split() Function---Splitting Strings
510(2)
Splitting on Multiple Alternative Delimiters
512(3)
The preg_grep() Function
515(2)
Getting Control---The RegEx Metacharacters
517(3)
Anchoring Metacharacters
520(4)
Matching Single Characters and Digits
524(6)
Metasymbols
530(3)
Metacharacters to Repeat Pattern Matches
533(10)
Metacharacters for Alternation
543(1)
Grouping or Clustering
544(1)
Remembering or Capturing
545(3)
Searching, Capturing, and Replacing
548(2)
Positive Lookahead
550(2)
Positive Lookbehind
552(1)
Commenting Regular Expressions and the x Modifier
553(1)
Searching for Patterns in Text Files
554(2)
Form Validation with PHP
556(1)
Checking for a Valid E-Mail Address
557(5)
Help on the Web
562(3)
Chapter Summary
565(2)
What You Should Know
565(1)
What's Next?
565(1)
Chapter 12 Lab
566(1)
Introduction to MySQL
567(28)
About Databases
567(3)
Client/Server Databases
568(1)
Talking to the Database
568(1)
MySQL Strengths and Weaknesses
569(1)
Easy to Use
569(1)
Large Community of Developers
569(1)
Open Source License
569(1)
Commercial License
569(1)
Scalability
570(1)
The Anatomy of a Relational Database
570(5)
The Database Server
571(1)
The Database
571(1)
Tables
571(1)
Records and Fields
572(1)
Columns/Fields
573(1)
Rows/Records
574(1)
Primary Key and Indexes
574(1)
The Database Schema
575(1)
Connecting to the Database
575(7)
MySQL Command-Line Options
576(3)
Graphical User Tools
579(1)
The phpMyAdmin Tool
579(1)
The MySQL Query Browser
580(2)
The MySQL Privilege System
582(11)
Logging into the Database Server
582(1)
Finding the Databases
583(2)
The ``user'' Table
585(1)
The ``db'' Table
586(1)
The ``host'' Table
587(1)
A Real-World Example
588(1)
The Grant and Revoke Commands
589(1)
Creating and Dropping a Database
590(2)
Some Useful MySQL Functions
592(1)
Chapter Summary
593(2)
What You Should Know
594(1)
What's Next?
594(1)
SQL Language Tutorial
595(52)
What Is SQL?
595(8)
Standarizing SQL
596(1)
Executing SQL Statements
596(1)
The MySQL Query Browser
597(1)
About SQL Commands/Queries
597(1)
English-Like Grammar
597(1)
Semicolons Terminate SQL Statements
598(1)
Naming Conventions
599(1)
Reserved Words
599(1)
Case Senstivity
599(1)
The Result-Set
600(1)
SQL and the Database
600(1)
The Show Databases Command
600(1)
USE Command
601(1)
SQL Database Tables
601(1)
The Show and Describe Commands
602(1)
SQL Data Manipulation Language (DML)
603(17)
The Select Command
604(1)
Select Specified Columns
604(1)
Select All Columns
605(1)
The Select Distinct Statement
605(1)
Limiting the Number of Lines in the Result-Set with Limit
606(2)
The Where Clause
608(1)
Using Quotes
609(1)
Using the = and <> Operators
609(1)
What Is Null?
609(2)
The > and < Operators
611(1)
The And and Or Operators
612(1)
The Like and Not Like Condition
613(1)
Pattern Matching and the % Wildcard
613(2)
The_ Wildcard
615(1)
The Between Statement
615(1)
Sorting Results with Order By
616(1)
The Insert Command
617(1)
The Update Command
618(1)
The Delete Statement
619(1)
SQL Data Definition Language
620(13)
Creating the Database
620(1)
SQL Data Types
621(2)
Creating a Table
623(2)
Creating a Key
625(1)
Primary Keys
625(2)
Foreign Keys
627(1)
Relations
628(1)
Two Tables with a Common Key
628(1)
Using a Fully Qualified Name and a Dot to Join the Tables
629(1)
Aliases
630(1)
Altering a Table
631(2)
Dropping a Table
633(1)
Dropping a Database
633(1)
SQL Functions
633(9)
Numeric Functions
634(1)
Using Group By
635(2)
String Functions
637(1)
Date and Time Functions
638(1)
Formatting the Date and Time
639(2)
The MySQL Extract Command
641(1)
Chapter Summary
642(5)
What You Should Know
642(1)
What's Next?
643(1)
Lab
643(4)
PHP and MySQL Integration
647(26)
Introduction
647(16)
Connecting to the Database Server
647(2)
Choosing the Database
649(1)
Executing SQL Statements (Insert, Update, Delete)
650(3)
Retrieving the Query Results (Select)
653(1)
The mysql_fetch_row() Function
653(2)
The mysql_fetch_assoc() Function
655(2)
Other Useful MySQL Functions
657(1)
The mysql_error() Function
658(2)
The mysql_num_rows() Function
660(1)
The mysql_num_fields() Function
661(1)
The mysql_field_name() Function
661(2)
The Guest Book Example
663(8)
Step 1: Designing the Database
663(2)
Step 2: Posting a Message Page
665(4)
Step 3: Listing All Messages
669(1)
Example Summary
670(1)
Chapter Summary
671(2)
What You Should Know
671(1)
What's Next?
671(1)
Chapter 15 Lab
671(2)
Cookies and Sessions
673(66)
What Is Stateless?
673(1)
What Are Cookies?
673(4)
Cookie Ingredients
674(1)
The Attributes of a Cookie
675(1)
Name
675(1)
Expiration Date
676(1)
Domain Name
676(1)
Path
676(1)
Security
677(1)
PHP and Cookies
677(17)
Creating Cookies with the setcookie() Function
677(1)
The $_Cookie Global Array
678(3)
Storing Multiple Values in One Cookie---Serialization
681(2)
Tracking Visitors with Cookies
683(1)
Visitor Count Example
683(2)
Tracking the Visitor's Last Visit
685(3)
Extending the Life of a Cookie
688(1)
The time() Function
688(1)
The mktime() Function
689(1)
Buffering and HTTP Headers
689(2)
The ob_start() and ob_end_flush() Functions
691(2)
Output Buffering and php.ini
693(1)
Deleting a Cookie
693(1)
Using the Browser to Remove Cookies
693(1)
What Is a Session?
694(42)
Where to Store Sessions
696(2)
Starting a Cookie-Based Session
698(1)
The session_start() Function
698(1)
Registering a Session
699(1)
The $_Session Associative Array
700(2)
The session_register() Function
702(1)
Saving Arrays in a Session
702(4)
Session Cookie Functions and Configuration Options
706(2)
Setting Preferences with Sessions
708(3)
Remembering Users and Preferences over Multiple Pages
711(4)
Naming Sessions
715(2)
Sessions Without Cookies
717(1)
Using a Hidden Form Element
717(4)
Passing Session IDs with a Link
721(1)
The SID Constant
721(5)
Changing the Session ID
726(1)
Ending a Session
727(1)
Deleting Session Variables
727(1)
The session_write_close() Function
728(1)
The session_destroy() Function
728(1)
Cleaning up Session Files and Garbage Collection
729(1)
Session Runtime Configuration
730(1)
PHP Session Functions
730(1)
Implementing a Login System with Sessions
731(5)
Chapter Summary
736(3)
What You Should Know
737(1)
What's Next?
738(1)
Lab
738(1)
Objects
739(44)
What Are Objects?
739(2)
Objects and Classes
740(1)
Working with Classes
741(31)
Defining the Class
741(1)
Instantiating the Class
741(1)
What's ``new''?
742(1)
The Properties and Methods
742(1)
What's $this?
743(1)
The -> Operator
743(1)
The gettype() and get_class() Functions
744(2)
Creating a Complete Class
746(1)
Displaying an Object
747(1)
Functions for Getting Class Information
748(1)
Encapsulation and Information Hiding
749(1)
Class Members and Scope
750(1)
Public Scope
750(1)
Private Scope
750(1)
Protected Scope
751(1)
Example Using Private Scope
751(2)
Magic Methods
753(1)
Constructors
753(3)
Destructors
756(2)
Accessor Methods---Setters and Getters
758(5)
Inheritance
763(1)
Constructors and Inheritance
763(3)
Overriding Methods
766(2)
Protected Access
768(4)
Some PHP 5 Object Features
772(8)
final Classes and Methods
772(1)
Static Members
773(1)
Class Constants
774(2)
Reusing a Class
776(4)
Chapter Summary
780(3)
What You Should Know
780(1)
Chapter 17 Lab
781(2)
Building an Art Gallery
783(26)
Project Overview
783(1)
The Public and the Private
783(2)
Creating the Web Site
785(20)
Creating the Database
785(1)
Administration Pages
786(1)
Listing All the Artists from the Database (admin_artlist.php)
786(2)
Updating an Artist in the Gallery (admin_artist_edit.php)
788(3)
Adding a New Artist to the Gallery (admin_artist_insert.php)
791(2)
Adding and/or Editing a Piece of Art (admin_art_edit.php)
793(4)
Public Pages
797(1)
The Header Page (header.php)
797(1)
The Index Page (index.php)
798(2)
The Detail Page (artist_detail.php)
800(2)
The Contact Us Page (contact.php)
802(1)
Securing Pages with Login
803(2)
Installing the Art Gallery
805(3)
Where to Find the Files for the Canvas Gallery Site
805(1)
Installing the MySQL Database
806(2)
Editing the PHP Pages
808(1)
Conclusion
808(1)
PHP and E-Mail
809(10)
The Mail Server
809(1)
MIME (Multipurpose Internet Mail Extensions)
810(1)
Runtime Configuration Options
810(1)
The mail() Function
811(1)
Sending a Simple E-Mail Message
811(2)
Example: Sending an HTML Message
813(6)
Sending a Message with an Attachment
814(5)
PHP and Date/Time
819(14)
Formatting Dates and Times
819(5)
The date() Function
819(3)
The strftime() Function
822(2)
Getting the Timestamp
824(5)
The time() Function
824(1)
The mktime() Function
825(3)
Creating a UNIX Timestamp from a String
828(1)
Getting the Date and Time
829(4)
Validating Dates
831(2)
Security and Debugging
833(16)
About Security
833(1)
Network Security and SSL
833(1)
Operating System, Web Server, and File System Security
834(1)
Securing PHP and MySQL
834(7)
Basic PHP Security Principles
835(1)
Validate Form Fields
835(1)
About register_globals
835(2)
SQL Injections
837(1)
File Names
838(1)
Safe Mode
839(1)
The File System
839(1)
Log Everything
839(2)
Where to Get More Security Information
841(1)
Debugging
841(8)
Turn on the Error Reporting
841(1)
Fix the Parse Errors First
841(2)
Diagnostic Print Statements
843(2)
Fixing SQL Errors
845(2)
More on Debugging
847(2)
Installation Procedures
849(6)
About Web Servers
849(1)
Installing Apache on Windows
849(1)
Installing PHP on Windows
850(1)
Installing PHP on Linux/UNIX
851(1)
Installing PHP on Mac OS X
851(1)
Configuring Apache to use PHP Module (All Platforms)
851(2)
Testing PHP and Apache Installation
852(1)
Configuring php.ini (All Platforms)
853(1)
Installing MySQL on Windows
854(1)
Installing MySQL on Linux/UNIX
854(1)
Installing MySQL on Mac OS X
854(1)
Read the Manual
854(1)
Index 855

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

Over the past few years, students taking my Perl/CGI course continued to ask me when I would be graduating from CGI to PHP, and whether I would offer a course or write a PHP "by Example" book. I didn't really take the idea of a book seriously until attending a PHP/MySQL class here in San Francisco a few years ago, where I met Marko Gargenta, who was the teacher of that class and the inspiration for this book. We had lunch together and I mentioned to him that the girl sitting next to me in the class was a Web designer, with little programming experience. She was concerned that she couldn't keep up with the class and wondered if I knew where she could find a book that explained PHP for designers, not just programmers. Marko had heard similar concerns from his students. We talked about how to address this issue, and from that conversation, the seeds were sown for PHP and MySQL by Example. Although, theoretically, the Web designer/developer should need no PHP programming experience to change the content of a page, and the programmer should be concerned only with the logic, such as calculations, sending data to a database, and so on, they do not always work in isolation. For example, suppose a page is designed so that when the user enters bank information in an HTML form, a PHP program, after doing some calculations, finds that there are insufficient funds, and sends back an error in a bold red font. In such a case, PHP and HTML are integratedone to calculate and produce the error message, the other to display it in a bold red font. Keeping the design and program logic separated may be the goal, but it is often impossible with the complexities of today's Web development. And then there is the issue of the database management system. Where does the processed data get stored? Who designs the database and its tables? Who administers it? How does the information get from the Web page, to the PHP program, and then to the database? Enter MySQL. Is this yet another world in isolation? Since my first meeting with Marko, I was challenged to bring these technologies together. When Prentice Hall agreed to publish our book, the learning curve was steep, and after the initial draft was done, I began teaching "An Introduction to PHP and MySQL Programming" from the PDF version of that first draft. I noticed that more Web designers were signing up than programmers, and they came in with trepidation that it would be way over their heads. But with the real-world examples and labs we provided, they started to enjoy feelings of success on the first morning. It was wonderful to witness both designers and programmers sharing their experiences without the artificial boundary that has kept them isolated from each other in the workplace. The mission of PHP and MySQL by Exampleis to create a gentle yet thorough introduction to the shared power of PHP and MySQL, to make static HTML pages dynamic. The labs and exercises have been tested by myself, Marko, and our students. I think you will find this "by Example" book a helpful and complete guide, no matter what side of the Web site you support, or even if you are just starting your own. Acknowledgments Many people helped with the creation of this book. I'd like to thank Mark L. Taub, my longtime editor at Prentice Hall; Vanessa Moore, the most gifted compositor on the planet; and Julie Nahil, a great production editor. Matthew Leingang, Sander van Zoest, David Mercer, and Jason Wertz provided extremely helpful manuscript reviews. Any remaining mistakes are my own. I'd also like to thank the students in my classes who provided valuable input for the labs. These include Rita McCue, Sanjay Shahri, Ryan Belcher, Debra Anderson, and Catherine Nguyen. The fantastic illustrations in the book were created by Elizabeth Staechelin and Daniel Staechelin. And many thanks to the artists who provided artwork for the art gallery example. They are Elliott Easterling, Laura Blair, Stuart Sheldon, and Todd Brown. Errata and solutions to the labs can be found on the book's Web site atwww.prenhallprofessional.com/title/0131875086. The Northwind database script, used in the chapters, can be found athttp://marakana.com/download/sql/northwind.sql. Ellie Quigley San Francisco, California September 2006

Rewards Program