Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Learning PHP, MySQL, and JavaScript
Preface
Audience
Assumptions This Book Makes
Organization of This Book
Supporting Books
Conventions Used in This Book
Using Code Examples
We’d Like to Hear from You
Safari® Books Online
Acknowledgments
1. Introduction to Dynamic Web Content
HTTP and HTML: Berners-Lee’s Basics
The Request/Response Procedure
The Benefits of PHP, MySQL, and JavaScript
Using PHP
Using MySQL
Using JavaScript
The Apache Web Server
About Open Source
Bringing It All Together
Test Your Knowledge: Questions
2. Setting Up a Development Server
What Is a WAMP, MAMP, or LAMP?
Installing a WAMP on Windows
Overcoming Installation Problems
Testing the Installation
Alternative WAMPs
Installing a MAMP on Mac OS X
Some Final Tweaking
Other Alternatives
Installing a LAMP on Linux
Working Remotely
Logging In
Using FTP
Using a Program Editor
Using an IDE
Test Your Knowledge: Questions
3. Introduction to PHP
Incorporating PHP Within HTML
Calling the PHP Parser
This Book’s Examples
The Structure of PHP
Using Comments
Basic Syntax
Semicolons
The $ symbol
Understanding Variables
String variables
Numeric variables
Arrays
Two-dimensional arrays
Variable naming rules
Operators
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Variable Assignment
Variable incrementing and decrementing
String concatenation
String types
Escaping characters
Multiple-Line Commands
Variable Typing
Constants
Predefined constants
The Difference Between the echo and print Commands
Functions
Variable Scope
Local variables
Global variables
Static variables
Superglobal variables
Superglobals and security
Test Your Knowledge: Questions
4. Expressions and Control Flow in PHP
Expressions
Literals and Variables
Operators
Operator Precedence
Associativity
Relational Operators
Equality
Comparison operators
Logical operators
Conditionals
The if Statement
The else Statement
The elseif Statement
The switch Statement
Breaking out
Default action
Alternative syntax
The ? Operator
Looping
while Loops
do...while Loops
for Loops
Breaking Out of a Loop
The continue Statement
Implicit and Explicit Casting
PHP Dynamic Linking
Dynamic Linking in Action
Test Your Knowledge: Questions
5. PHP Functions and Objects
PHP Functions
Defining a Function
Returning a Value
Returning an Array
Passing by Reference
Returning Global Variables
Recap of Variable Scope
Including and Requiring Files
The include Statement
Using include_once
Using require and require_once
PHP Version Compatibility
PHP Objects
Terminology
Declaring a Class
Creating an Object
Accessing Objects
Cloning objects
Constructors
PHP 5 destructors
Writing Methods
Static methods in PHP 5
Declaring Properties
Declaring Constants
Property and Method Scope in PHP 5
Static properties and methods
Inheritance
The parent operator
Subclass constructors
Final methods
Test Your Knowledge: Questions
6. PHP Arrays
Basic Access
Numerically Indexed Arrays
Associative Arrays
Assignment Using the array Keyword
The foreach...as Loop
Multidimensional Arrays
Using Array Functions
is_array()
count()
sort()
shuffle()
explode()
extract()
compact()
reset()
end()
Test Your Knowledge: Questions
7. Practical PHP
Using printf
Precision Setting
String Padding
Using sprintf
Date and Time Functions
Date Constants
Using checkdate
File Handling
Checking Whether a File Exists
Creating a File
Reading from Files
Copying Files
Moving a File
Deleting a File
Updating Files
Locking Files for Multiple Accesses
Reading an Entire File
Uploading Files
Using $_FILES
Validation
System Calls
XHTML
The Benefits of XHTML
XHTML Versions
What’s Different?
HTML 4.01 Document Types
XHTML 1.0 Document Types
XHTML Validation
Test Your Knowledge: Questions
8. Introduction to MySQL
MySQL Basics
Summary of Database Terms
Accessing MySQL via the Command Line
Starting the Command-Line Interface
Windows users
Mac OS X users
Linux users
MySQL on a remote server
Using the Command-Line Interface
The semicolon
Canceling a command
MySQL Commands
Creating a database
Creating users
Creating a table
Data Types
The CHAR data type
The BINARY data type
The TEXT and VARCHAR data types
The BLOB data type
Numeric data types
DATE and TIME
The AUTO_INCREMENT data type
Adding data to a table
Renaming a table
Changing the data type of a column
Adding a new column
Renaming a column
Removing a column
Deleting a table
Indexes
Creating an Index
Using CREATE INDEX
Adding indexes when creating tables
Primary keys
Creating a FULLTEXT index
Querying a MySQL Database
SELECT
SELECT COUNT
SELECT DISTINCT
DELETE
WHERE
LIMIT
MATCH...AGAINST
MATCH...AGAINST...IN BOOLEAN MODE
UPDATE...SET
ORDER BY
GROUP BY
Joining Tables Together
NATURAL JOIN
JOIN...ON
Using AS
Using Logical Operators
MySQL Functions
Accessing MySQL via phpMyAdmin
Windows Users
Mac OS X Users
Linux Users
Using phpMyAdmin
Test Your Knowledge: Questions
9. Mastering MySQL
Database Design
Primary Keys: The Keys to Relational Databases
Normalization
First Normal Form
Second Normal Form
Third Normal Form
When Not to Use Normalization
Relationships
One-to-One
One-to-Many
Many-to-Many
Databases and Anonymity
Transactions
Transaction Storage Engines
Using BEGIN
Using COMMIT
Using ROLLBACK
Using EXPLAIN
Backing Up and Restoring
Using mysqldump
Creating a Backup File
Restoring from a Backup File
Dumping Data in CSV Format
Planning Your Backups
Test Your Knowledge: Questions
10. Accessing MySQL Using PHP
Querying a MySQL Database with PHP
The Process
Creating a Login File
Connecting to MySQL
Selecting a database
Building and executing a query
Fetching a result
Fetching a row
Closing a connection
A Practical Example
The $_POST Array
Deleting a Record
Displaying the Form
Querying the Database
Running the Program
Practical MySQL
Creating a Table
Describing a Table
Dropping a Table
Adding Data
Retrieving Data
Updating Data
Deleting Data
Using AUTO_INCREMENT
Using insert IDs
Performing Additional Queries
Preventing SQL Injection
Using placeholders
Preventing HTML Injection
Test Your Knowledge: Questions
11. Form Handling
Building Forms
Retrieving Submitted Data
register_globals: An Old Solution Hangs On
Default Values
Input Types
Text Boxes
Text Areas
Checkboxes
Radio Buttons
Hidden Fields
Select
Labels
The submit button
Sanitizing Input
An Example Program
Test Your Knowledge: Questions
12. Templating with Smarty
Why Smarty?
Installation
Creating Scripts
Creating Templates
A Practical Example
Test Your Knowledge: Questions
13. Cookies, Sessions, and Authentication
Using Cookies in PHP
Setting a Cookie
Accessing a Cookie
Destroying a Cookie
HTTP Authentication
Storing Usernames and Passwords
Salting
Using Sessions
Starting a Session
Ending a Session
Setting a timeout
Session Security
Preventing session hijacking
Preventing session fixation
Forcing cookie-only sessions
Using a shared server
Test Your Knowledge: Questions
14. Exploring JavaScript
JavaScript and HTML Text
Using Scripts Within a Document Head
Older and Nonstandard Browsers
Including JavaScript Files
Debugging JavaScript Errors
Using Comments
Semicolons
Variables
String Variables
Numeric Variables
Arrays
Operators
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Variable Incrementing and Decrementing
String Concatenation
Escaping Characters
Variable Typing
Functions
Global Variables
Local Variables
The Document Object Model
Browser Incompatibilities
Another use for the $ sign
Using the DOM
Test Your Knowledge: Questions
15. Expressions and Control Flow in JavaScript
Expressions
Literals and Variables
Operators
Operator Precedence
Associativity
Relational Operators
Equality operators
Comparison operators
Logical operators
The with Statement
Using onError
Using try...catch
Conditionals
The if Statement
The else statement
The switch Statement
Breaking out
Default action
The ? Operator
Looping
while Loops
do...while Loops
for Loops
Breaking Out of a Loop
The continue Statement
Explicit Casting
Test Your Knowledge: Questions
16. JavaScript Functions, Objects, and Arrays
JavaScript Functions
Defining a Function
The arguments array
Returning a Value
Returning an Array
JavaScript Objects
Declaring a Class
Creating an Object
Accessing Objects
The prototype Keyword
Static methods and properties
Extending JavaScript objects
JavaScript Arrays
Numeric Arrays
Assigning element values
Assignment using the array keyword
Associative Arrays
Multidimensional Arrays
Using Array Methods
concat
forEach: For non-IE browsers
forEach: A cross-browser solution
join
push and pop
Using reverse
sort
Test Your Knowledge: Questions
17. JavaScript and PHP Validation and Error Handling
Validating User Input with JavaScript
The validate.html Document (Part One)
How it works
The validate.html Document (Part Two)
Validating the forename
Validating the surname
Validating the username
Validating the password
Validating the age
Validating the email
Using a separate JavaScript file
Regular Expressions
Matching Through Metacharacters
Fuzzy Character Matching
Grouping Through Parentheses
Character Classes
Indicating a Range
Negation
Some More Complicated Examples
Summary of Metacharacters
General Modifiers
Using Regular Expressions in JavaScript
Using Regular Expressions in PHP
Redisplaying a Form After PHP Validation
Test Your Knowledge: Questions
18. Using Ajax
What Is Ajax?
Using XMLHttpRequest
Your First Ajax Program
The readyState property
The server half of the Ajax process
Using GET Instead of POST
Sending XML Requests
About XML
Why use XML?
Test Your Knowledge: Questions
19. Using YUI for Ajax and More
Choosing a Framework
Using YUI
Compressed Versions
Using YUI for Ajax
Including the framework files
The YUI asyncRequest method
An Ajax GET example using YUI
An Ajax XML example using YUI
Other Uses for YUI
A Simple YUI Calendar
Test Your Knowledge: Questions
20. Bringing It All Together
Designing a Social Networking Site
About Third-Party Add-Ons
On the Website
rnfunctions.php
The Functions
rnheader.php
rnsetup.php
index.php
rnsignup.php
Checking for Username Availability
rnsignup.php (YUI version)
rncheckuser.php
rnlogin.php
rnprofile.php
Adding the “About Me” Text
Adding a Profile Image
Processing the Image
Displaying the Current Profile
rnmembers.php
Viewing a User’s Profile
Adding and Dropping Friends
Listing All Members
rnfriends.php
rnmessages.php
rnlogout.php
A. Solutions to the Chapter Questions
Chapter 1 Answers
Chapter 2 Answers
Chapter 3 Answers
Chapter 4 Answers
Chapter 5 Answers
Chapter 6 Answers
Chapter 7 Answers
Chapter 8 Answers
Chapter 9 Answers
Chapter 10 Answers
Chapter 11 Answers
Chapter 12 Answers
Chapter 13 Answers
Chapter 14 Answers
Chapter 15 Answers
Chapter 16 Answers
Chapter 17 Answers
Chapter 18 Answers
Chapter 19 Answers
B. Online Resources
PHP Resource Sites
MySQL Resource Sites
JavaScript Resource Sites
Ajax Resource Sites
Miscellaneous Resource Sites
O’Reilly Resource Sites
C. MySQL’s FULLTEXT Stopwords
D. MySQL Functions
String Functions
CONCAT()
CONCAT_WS()
LEFT()
RIGHT()
MID()
LENGTH()
LPAD()
RPAD
LOCATE()
LOWER()
UPPER()
QUOTE()
REPEAT()
REPLACE()
TRIM()
LTRIM() and RTRIM()
Date Functions
CURDATE()
DATE()
DATE_ADD()
DATE_FORMAT()
DAY()
DAYNAME()
DAYOFWEEK()
DAYOFYEAR()
LAST_DAY()
MAKEDATE()
MONTH()
MONTHNAME()
SYSDATE()
YEAR()
WEEK()
WEEKDAY()
Time Functions
CURTIME()
HOUR()
MINUTE()
SECOND()
MAKETIME()
TIMEDIFF()
UNIX_TIMESTAMP()
FROM_UNIXTIME()
E. Using PEAR and PHPUnit
Installation
Windows
Mac OS
Linux/Unix
Creating a Connect Instance
Querying
Fetching a Row
Closing a Connection
Rewriting Example 10-8 to Use PEAR
Adding Other PEAR Packages
Unit Testing with PHPUnit
Index
Colophon
← Prev
Back
Next →
← Prev
Back
Next →