PHP6 and MySQL Bible
About the Authors
Credits
Acknowledgments
Contents at a Glance
Contents
Introduction
What Is PHP?
Why PHP?
What’s New in This Edition?
Whom This Book Is For
This Book Is Not the Manual
How the Book Is Organized
Conventions Used in This Book
What the Icons Mean
Part I: Introducing PHP
Chapter 1: Why PHP and MySQL?
What Is PHP?
What Is MySQL?
Deciding on a Web Application Platform
Summary
Chapter 2: Server-Side Scripting Overview
Static HTML
Client-Side Technologies
Server-Side Scripting
What Is Server-Side Scripting Good For?
Summary
Chapter 3: Getting Started with PHP
Installing PHP
What’s to Come?
Your HTML Is Already PHP-Compliant!
Escaping from HTML
Summary
Chapter 4: Learning PHP Syntax and Variables
PHP Is Forgiving
HTML Is Not PHP
PHP’s Syntax Is C-Like
Comments
Variables
Types in PHP: Don’t Worry, Be Happy
Type Summary
The Simple Types
Output
Summary
Chapter 5: Learning PHP Control Structures and Functions
Boolean Expressions
Branching
Looping
Alternate Control Syntaxes
Terminating Execution
Using Functions
Function Documentation
Defining Your Own Functions
Functions and Variable Scope
Function Scope
Summary
Chapter 6: Passing Information with PHP
HTTP Is Stateless
GET Arguments
A Better Use for GET-Style URLs
POST Arguments
Formatting Form Variables
PHP Superglobal Arrays
Summary
Chapter 7: Learning PHP String Handling
Strings in PHP
String Functions
Summary
Chapter 8: Learning Arrays
The Uses of Arrays
What Are PHP Arrays?
Creating Arrays
Retrieving Values
Multidimensional Arrays
Inspecting Arrays
Deleting from Arrays
Iteration
Summary
Chapter 9: Learning PHP Number Handling
Numerical Types
Mathematical Operators
Simple Mathematical Functions
Randomness
Summary
Chapter 10: PHP Gotchas
Installation-Related Problems
Rendering Problems
Failures to Load Page
Parse Errors
Missing Includes
Unbound Variables
Function Problems
Math Problems
Timeouts
Summary
Part II: MySQL Database Integration
Chapter 11: Introducing Databases and MySQL
What Is a Database?
Why a Database?
PHP-Supported Databases
Our Focus: MySQL
Summary
Chapter 12: Installing MySQL
Obtaining MySQL
Installing MySQL on Linux
Installing MySQL on Microsoft Windows
Summary
Chapter 13: Learning Structured Query Language (SQL)
Relational Databases and SQL
SQL Standards
The Workhorses of SQL
Database Design
Privileges and Security
Summary
Chapter 14: Learning Database Administration and Design
Basic MySQL Client Commands
MySQL User Administration
Backups
Replication
Recovery
Summary
Chapter 15: Integrating PHP and MySQL
Connecting to MySQL
Making MySQL Queries
Fetching Data Sets
Getting Data about Data
Multiple Connections
Building in Error Checking
Creating MySQL Databases with PHP
MySQL Functions
Summary
Chapter 16: Performing Database Queries
HTML Tables and Database Tables
Complex Mappings
Creating the Sample Tables
Summary
Chapter 17: Integrating Web Forms and Databases
HTML Forms
Basic Form Submission to a Database
Self-Submission
Editing Data with an HTML Form
Summary
Chapter 18: Improving Database Efficiency
Connections—Reduce, Reuse, Recycle
Indexing and Table Design
Making the Database Work for You
Summary
Chapter 19: MySQL Gotchas
No Connection
Problems with Privileges
Unescaped Quotes
Broken SQL Statements
Too Little Data, Too Much Data
Specific SQL Functions
Debugging and Sanity Checking
Summary
Part III: More PHP
Chapter 20: Introducing Object-Oriented PHP
What Is Object-Oriented Programming?
Basic PHP Constructs for OOP
Advanced OOP Features
Introspection Functions
Extended Example: HTML Forms
Gotchas and Troubleshooting
OOP Style in PHP
Summary
Chapter 21: Advanced Array Functions
Transformations of Arrays
Stacks and Queues
Translating between Variables and Arrays
Sorting
Printing Functions for Visualizing Arrays
Summary
Chapter 22: Examining Regular Expressions
Tokenizing and Parsing Functions
Why Regular Expressions?
Perl-Compatible Regular Expressions
Example: A simple link-scraper
Advanced String Functions
Summary
Chapter 23: Working with the Filesystem
Understanding PHP File Permissions
File Reading and Writing Functions
Filesystem and Directory Functions
Network Functions
Date and Time Functions
Calendar Conversion Functions
Summary
Chapter 24: Working with Cookies and Sessions
What’s a Session?
Home-grown Alternatives
How Sessions Work in PHP
Sample Session Code
Session Functions
Configuration Issues
Cookies
Sending HTTP Headers
Gotchas and Troubleshooting
Summary
Chapter 25: Learning PHP Types
Type Round-up
Resources
Type Testing
Assignment and Coercion
Summary
Chapter 26: Learning PHP Advanced Functions
Variable Numbers of Arguments
Call-by-value
Call-by-reference
Variable function names
An extended example
Summary
Chapter 27: Performing Math with PHP
Mathematical Constants
Tests on Numbers
Base Conversion
Exponents and Logarithms
Trigonometry
Arbitrary Precision (BC)
Summary
Chapter 28: Securing PHP
Possible Attacks
FYI: Security Web Sites
Summary
Chapter 29: Learning PHP Configuration
Viewing Environment Variables
Understanding PHP Configuration
Improving PHP Performance
Summary
Chapter 30: Handing Exceptions with PHP
Error Handling in PHP
Other Methods of Error Handling
Logging and Debugging
Summary
Chapter 31: Debugging PHP Programs
General Troubleshooting Strategies
A Menagerie of Bugs
Using Web Server Logs
PHP Error Reporting and Logging
Error-Reporting Functions
Summary
The Uses of Style
Chapter 32: Learning PHP Style
Readability
Maintainability
Robustness
Efficiency and Conciseness
HTML Mode or PHP Mode?
Separating Code from Design
Summary
Part IV: Other Databases
Chapter 33: Connecting PHP and PostgreSQL
Why Choose PostgreSQL?
Why Object-Relational Anyway?
Down to Real Work
PHP and PostgreSQL
The Cartoons Database
Summary
Chapter 34: Using PEAR DB with PHP
Pear DB Concepts
PEAR DB Functions
Summary
Chapter 35: An Overview of Oracle
When Do You Need Oracle?
Oracle and Web Architecture
Using OCI8 Functions
Project: Point Editor
Project: Batch Editor
Summary
Chapter 36: An Introduction to SQLite
An Introduction to SQLite
Using SQLite-related Functions
More on SQLite
Summary
Part V: Connections
Chapter 37: Sending E-Mail with PHP
Sending E-Mail with PHP
Sending Mail from a Form
Summary
Chapter 38: Integrating PHP and Java
PHP for Java programmers
Integrating PHP and Java
Summary
Chapter 39: Integrating PHP and JavaScript
Outputting JavaScript with PHP
PHP as a Backup for JavaScript
Static versus Dynamic JavaScript
Summary
Chapter 40: Integrating PHP and XML
What Is XML?
Working with XML
Documents and DTDs
SAX versus DOM
DOM
SAX
SimpleXML API
A Sample XML Application
Gotchas and Troubleshooting
Summary
Chapter 41: Creating and Consuming Web Services with PHP
The End of Programming as We Know It
REST, XML-RPC, SOAP, . NET
Current Issues with Web Services
Project: A REST Client
Summary
Chapter 42: Creating Graphics with PHP
Your Options
HTML Graphics
Creating images using gd
Gotchas and Troubleshooting
Summary
Part VI: Case Studies
Chapter 43: Developing a Weblog with PHP
Why Weblogs?
The Simplest Weblog
Adding an HTML-Editing Tool
Changes and Additions
Summary
Chapter 44: A Trivia Game
Concepts Used in This Chapter
The Game
The Code
General Design Considerations
Summary
Chapter 45: Data Visualization with Venn Diagrams
Scaled Venn diagrams
Outline of the code
Necessary Trigonometry
Planning the Display
Display
Visualizing a Database
Extensions
Summary
Appendix A: PHP for C Programmers
Similarities
Differences
Guide to the Book
A Bonus: Just Look at the Code!
Appendix B: PHP for Perl Hackers
Similarities
Differences
Miscellaneous Tips
Guide to the Book
Appendix C: PHP for HTML Coders
The Good News
The Bad News
Concentrate On . . .
Avoid at First . . .
Consider This . . .
Appendix D: PHP Resources
The PHP Web Site
The PHP Mailing Lists
Other PHP Web Sites
Appendix E: PEAR
What Is PEAR?
The PEAR Package System
PHP Foundation Classes (PFC)
PHP Extension Code Library (PECL)
The PEAR Coding Style
Summary
Index