Sams Teach Yourself PHP MySQL and Apache All in One.pdf

(4422 KB) Pobierz
.
1
I
I:
intern
-ÿ>
-
ESR
-
-
r
A
each
Yourself
PHP,
MySQL
and
Apache
4Hte
SAMS
Teach Yourself
PHP, MySQL
and Apache
Julie C. Meloni
®
All
in
One
800 East 96th Street, Indianapolis, Indiana, 46240 USA
SAMS
Sams Teach Yourself PHP, MySQL and Apache
All in One
Copyright © 2004 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a
retrieval system, or transmitted by any means, electronic, mechanical,
photocopying, recording, or otherwise, without written permission from
the publisher. No patent liability is assumed with respect to the use of
the information contained herein. Although every precaution has been
taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions. Nor is any liability assumed for
damages resulting from the use of the information contained herein.
International Standard Book Number: 0-672-32620-5
Library of Congress Catalog Card Number: 2003109401
Printed in the United States of America
First Printing: December 2003
06
05
04
03
4
3
2
1
Acquisitions Editor
Shelley Johnston
Development Editor
Chris Newman
Managing Editor
Charlotte Clapp
Project Editor
Dan Knott
Copy Editor
Krista Hansing
Indexer
Sharon Shock
Proofreader
Mike Henry
Technical Editor
Chris Newman
Publishing Coordinator
Vanessa Evans
Multimedia Developer
Dan Scherf
Designer
Gary Adair
Page Layout
Julie Parks
Trademarks
All terms mentioned in this book that are known to be trademarks or
service marks have been appropriately capitalized. Sams Publishing
cannot attest to the accuracy of this information. Use of a term in this
book should not be regarded as affecting the validity of any trademark
or service mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accu-
rate as possible, but no warranty or fitness is implied. The information
provided is on an “as is” basis. The author and the publisher shall have
neither liability nor responsibility to any person or entity with respect to
any loss or damages arising from the information contained in this
book or from the use of the CD or programs accompanying it.
Bulk Sales
Sams Publishing offers excellent discounts on this book when ordered in
quantity for bulk purchases or special sales. For more information,
please contact
U.S. Corporate and Government Sales
1-800-382-3419
corpsales@pearsontechgroup.com
For sales outside of the U.S., please contact
International Sales
+1-317-428-3341
international@pearsontechgroup.com
Contents at a Glance
Introduction
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
Part I: Laying the Groundwork
CHAPTER 1
Installing and Configuring MySQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2
Installing and Configuring Apache
......................................
27
3
Installing and Configuring PHP
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
51
Part II: PHP Language Structure
CHAPTER 4
The Building Blocks of PHP
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
71
5
Flow Control Functions in PHP
93
6
Working with Functions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
115
7
Working with Arrays and Objects
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
135
.............................................
Part III: Getting Involved with the Code
CHAPTER 8
Working with Strings, Dates and Time
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
153
9
Working with Forms
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
181
10
Working with User Sessions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
203
11
Working with Files and Directories
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
213
12
Working with the Server Environment
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
237
13
Working with Images
.........................................................
245
Part IV: PHP and MySQL Integration
CHAPTER 14
Learning the Database Design Process
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
262
15
Learning Basic SQL Commands
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
273
16
Interacting with MySQL Using PHP
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
321
Part V: Basic Projects
CHAPTER 17
Managing a Simple Mailing List
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
335
18
Creating an Online Address Book
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
347
19
Creating a Simple Discussion Forum
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
371
20
Creating an Online Storefront
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
387
21
Creating a Shopping Cart Mechanism
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
399
22
Creating a Simple Calendar
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
413
23
Restricting Access to Your Applications
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
427
24
Logging and Monitoring Web Server Activity
. . . . . . . . . . . . . . . . . . . . . .
449
25
Application Localization
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
467
Part VI: Administration and Fine Tuning
CHAPTER 26
Apache Performance Tuning and Virtual Hosting
. . . . . . . . . . . . . . .
481
27
Setting Up a Secure Web Server
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
499
28
Optimizing and Tuning MySQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
515
29
Software Upgrades
.............................................................
533
Part VII: Looking Toward the Future
CHAPTER 30
Features and Backwards-Compatibility of PHP 5.0
541
31
Features and Backwards-Compatibility of MySQL 4.1
. . . . . . . . . .
547
..............
Part VIII: Appendix
APPENDIX A
Installing MySQL, Apache, and PHP from the CD-ROM
. . . . . .
557
Index
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
569
Zgłoś jeśli naruszono regulamin