Wrox Press Beginning PHP6 Apache MySQL 6 Web Development (2009).pdf

(7241 KB) Pobierz
Beginning
PHP6, Apache, MySQL ® Web Development
Timothy Boronczyk
Elizabeth Naramore
Jason Gerner
Yann Le Scouarnec
Jeremy Stolz
Michael K. Glass
Wiley Publishing, Inc.
993021767.050.png 993021767.054.png 993021767.055.png 993021767.056.png 993021767.001.png 993021767.002.png 993021767.003.png 993021767.004.png 993021767.005.png 993021767.006.png 993021767.007.png 993021767.008.png 993021767.009.png
Beginning PHP6, Apache, MySQL ® Web Development
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-39114-3
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data.
Beginning PHP6, Apache, MySQL web development / Timothy Boronczyk . . . [et al.].
p. cm.
Includes index.
ISBN 978-0-470-39114-3 (paper/website)
1. Web sites—Design.
2. Apache (Computer file : Apache Group)
3. PHP (Computer program
language)
4. MySQL (Electronic resource)
I. Boronczyk, Tim, 1979-
TK5105.888.B426 2009
006.7'8—dc22
2008047012
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted
under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written
permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the
Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600.
Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley &
Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at
http://www.wiley.com/go/permissions .
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or
warranties with respect to the accuracy or completeness of the contents of this work and specifically
disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No
warranty may be created or extended by sales or promotional materials. The advice and strategies contained
herein may not be suitable for every situation. This work is sold with the understanding that the publisher is
not engaged in rendering legal, accounting, or other professional services. If professional assistance is
required, the services of a competent professional person should be sought. Neither the publisher nor the
author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in
this work as a citation and/or a potential source of further information does not mean that the author or the
publisher endorses the information the organization or Web site may provide or recommendations it may
make. Further, readers should be aware that Internet Web sites listed in this work may have changed or
disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department
within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related
trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the
United States and other countries, and may not be used without written permission. MySQL is a registered
trademark of MySQL AB. All other trademarks are the property of their respective owners. Wiley
Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not
be available in electronic books.
993021767.010.png 993021767.011.png 993021767.012.png 993021767.013.png 993021767.014.png 993021767.015.png 993021767.016.png 993021767.017.png 993021767.018.png 993021767.019.png
Contents
Introduction
xxiii
Part I: Movie Review Web Site
Chapter 1: Configuring Your Installation
3
Projects in This Book
3
A Brief Introduction to Apache, MySQL, PHP, and Open Source
4
A Brief History of Open Source Initiatives
4
Why Open Source Rocks
5
How the AMP Pieces Work Together
5
Installing Apache, MySQL, and PHP on Windows
6
Installing Apache
6
Installing PHP
10
Configuring PHP to Use MySQL
11
Installing MySQL
13
Where to Go for Help and Other Valuable Resources
17
Help within the Programs
18
Source Web Sites
18
Summary
18
Chapter 2: Creating PHP Pages Using PHP6
19
Overview of PHP Structure and Syntax
20
How PHP Fits with HTML
20
The Rules of PHP Syntax
20
The Importance of Coding Practices
21
Creating Your First Program
23
Using HTML to Spice Up Your Pages
26
Integrating HTML with PHP
26
Considerations with HTML inside PHP
28
Using Constants and Variables to Add Functionality
29
Overview of Constants
29
Overview of Variables
31
Passing Variables between Pages
33
Passing Variables through a URL
33
993021767.020.png 993021767.021.png 993021767.022.png 993021767.023.png 993021767.024.png 993021767.025.png 993021767.026.png 993021767.027.png 993021767.028.png 993021767.029.png 993021767.030.png
Contents
Passing Variables with Sessions
38
Passing Variables with Cookies
41
Passing Information with Forms
44
Using if/else Arguments
49
Using if Statements
49
Using if and else Together
51
Using Includes for Efficient Code
52
Using Functions for Efficient Code
55
All about Arrays
59
Array Syntax
60
Sorting Arrays
61
foreach Constructs
63
While You’re Here . . .
67
Alternate Syntax for PHP
72
Alternates to the echo Command
72
Alternates to Logical Operators
73
Alternates to Double Quotes: Using heredoc
73
Alternates to Incrementing/Decrementing Values
73
OOP Dreams
74
Classes
74
Properties and Methods
75
Why Use OOP?
75
Summary
76
Exercises
76
Chapter 3: Using PHP with MySQL
77
Overview of MySQL Structure and Syntax
77
MySQL Structure
78
MySQL Syntax and Commands
84
How PHP Fits with MySQL
85
Connecting to the MySQL Server
86
Looking at a Ready-Made Database
86
Querying the Database
91
WHERE, oh WHERE
91
Working with PHP and Arrays of Data: foreach
94
A Tale of Two Tables
97
Helpful Tips and Suggestions
102
Documentation
102
Using MySQL Query Browser
102
Summary
103
Exercises
103
xvi
993021767.031.png 993021767.032.png 993021767.033.png 993021767.034.png 993021767.035.png 993021767.036.png 993021767.037.png 993021767.038.png 993021767.039.png 993021767.040.png 993021767.041.png
 
Contents
Chapter 4: Using Tables to Display Data
105
Creating a Table
105
Wait a Minute
110
Who’s the Master?
118
A Lasting Relationship
125
Summary
129
Exercises
129
Chapter 5: Form Elements: Letting the User Work with Data
131
Your First Form
131
FORM Element
134
INPUT Element
134
Processing the Form
135
Driving the User Input
135
One Form, Multiple Processing
139
Radio INPUT Element
142
Multiple Submit Buttons
143
Basic Input Testing
143
Ternary Operator
144
Linking Forms Together
145
Summary
151
Exercises
152
Chapter 6: Letting the User Edit the Database
153
Preparing the Battlefield
153
Inserting a Record in a Relational Database
156
Deleting a Record
162
Editing Data in a Record
167
Summary
174
Exercise
174
Chapter 7: Manipulating and Creating Images with PHP
175
Working with the GD Library
175
What File Types Can I Use with GD & PHP?
176
Enabling GD in PHP
176
Allowing Users to Upload Images
177
Converting Image File Types
188
Special Effects
192
Adding Captions
202
xvii
993021767.042.png 993021767.043.png 993021767.044.png 993021767.045.png 993021767.046.png 993021767.047.png 993021767.048.png 993021767.049.png 993021767.051.png 993021767.052.png 993021767.053.png
Zgłoś jeśli naruszono regulamin