PHP&MySQL(WellingThomson).pdf

(7377 KB) Pobierz
PHP and MySQL Web Development
PHP and MySQL
Web Development
Luke Welling and Laura Thomson
201 West 103rd St., Indianapolis, Indiana, 46290 USA
1273615.004.png 1273615.005.png 1273615.006.png
PHP and MySQL Web Development
Copyright © 2001 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, photo-
copying, recording, or otherwise, without written permission from the pub-
lisher. 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. Neither is any liability assumed for damages resulting from the use
of the information contained herein.
International Standard Book Number: 0-672-31784-2
Library of Congress Catalog Card Number: 99-64841
Printed in the United States of America
First Printing: March 2001
04 03 02 01
A CQUISITIONS E DITOR
Shelley Johnston Markanday
D EVELOPMENT E DITOR
Scott D. Meyers
M ANAGING E DITOR
Charlotte Clapp
C OPY E DITOR
Rhonda Tinch-Mize
I NDEXER
Kelly Castell
P ROOFREADERS
Kathy Bidwell
Tony Reitz
4 3 2 1
T ECHNICAL E DITORS
Israel Denis
Chris Newman
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.
T EAM C OORDINATOR
Amy Patton
S OFTWARE D EVELOPMENT
S PECIALIST
Dan Scherf
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as
possible, but no warranty or fitness is implied. The information provided is on
an “as is” basis. The authors and the publisher shall have neither liability nor
responsibility to any person or entity with respect to any loss or damages aris-
ing from the information contained in this book or from the use of the CD-
ROM or programs accompanying it.
I NTERIOR D ESIGN
Anne Jones
C OVER D ESIGN
Anne Jones
P RODUCTION
Ayanna Lacey
Heather Hiatt Miller
Stacey Richwine-DeRome
1273615.007.png
Overview
Introduction 1
P ART I Using PHP
1 PHP Crash Course 9
2 Storing and Retrieving Data 49
3 Using Arrays 69
4 String Manipulation and Regular Expressions 93
5 Reusing Code and Writing Functions 117
6 Object-Oriented PHP 147
P ART II Using MySQL
7 Designing Your Web Database 171
8 Creating Your Web Database 183
9 Working with Your MySQL Database 207
10 Accessing Your MySQL Database from the Web with PHP 227
11 Advanced MySQL 245
P ART III E-commerce and Security
12 Running an E-commerce Site 267
13 E-commerce Security Issues 281
14 Implementing Authentication with PHP and MySQL 303
15 Implementing Secure Transactions with PHP and MySQL 327
P ART IV Advanced PHP Techniques
16 Interacting with the File System and the Server 351
17 Using Network and Protocol Functions 369
18 Managing the Date and Time 391
19 Generating Images 401
20 Using Session Control in PHP 429
21 Other Useful Features 447
1273615.001.png
P ART V Building Practical PHP and MySQL Projects
22 Using PHP and MySQL for Large Projects 459
23 Debugging 477
24 Building User Authentication and Personalization 497
25 Building a Shopping Cart 539
26 Building a Content Management System 587
27 Building a Web-Based Email Service 617
28 Building a Mailing List Manager 655
29 Building Web Forums 711
30 Generating Personalized Documents in Portable Document Format (PDF) 743
P ART VI
A Installing PHP 4 and MySQL 781
B Web Resources 803
Index 807
1273615.002.png
Contents
Introduction 1
Who Should Read This Book? ..............................................................1
What Is PHP? ..........................................................................................1
What Is MySQL? ....................................................................................2
Why Use PHP and MySQL? ..................................................................2
Some of PHP’s Strengths ........................................................................3
Performance ......................................................................................3
Database Integration ..........................................................................3
Built-In Libraries ..............................................................................4
Cost ....................................................................................................4
Learning PHP ....................................................................................4
Portability ..........................................................................................4
Source Code ......................................................................................4
Some of MySQL’s Strengths ..................................................................4
Performance ......................................................................................5
Low Cost ..........................................................................................5
Ease of Use ........................................................................................5
Portability ..........................................................................................5
Source Code ......................................................................................5
How Is This Book Organized? ..............................................................5
What’s New in PHP Version 4? ..............................................................6
Finally ....................................................................................................6
P ART I Using PHP 7
1 PHP Crash Course 9
Using PHP ............................................................................................11
Sample Application: Bob’s Auto Parts ................................................11
The Order Form ..............................................................................11
Processing the Form ........................................................................13
Embedding PHP in HTML ..................................................................13
Using PHP Tags ..............................................................................14
PHP Tag Styles ................................................................................15
PHP Statements ..............................................................................15
Whitespace ......................................................................................16
Comments ........................................................................................16
Adding Dynamic Content ....................................................................17
Calling Functions ............................................................................18
The date() Function ........................................................................18
1273615.003.png
Zgłoś jeśli naruszono regulamin