Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Beginning PHP, Apache and MySQL Web Development
PREMIUM
Số trang
406
Kích thước
7.1 MB
Định dạng
PDF
Lượt xem
1807

Beginning PHP, Apache and MySQL Web Development

Nội dung xem thử

Mô tả chi tiết

Professional LAMP

Linux®, Apache, MySQL®,

and PHP5 Web Development

Jason Gerner

Elizabeth Naramore

Morgan L. Owens

Matt Warden

01_59723x ffirs.qxd 10/31/05 6:37 PM Page iii

Professional LAMP

01_59723x ffirs.qxd 10/31/05 6:37 PM Page i

01_59723x ffirs.qxd 10/31/05 6:37 PM Page ii

Professional LAMP

Linux®, Apache, MySQL®,

and PHP5 Web Development

Jason Gerner

Elizabeth Naramore

Morgan L. Owens

Matt Warden

01_59723x ffirs.qxd 10/31/05 6:37 PM Page iii

Professional LAMP: Linux®, Apache, MySQL®, and PHP5

Web Development

Published by

Wiley Publishing, Inc.

10475 Crosspoint Boulevard

Indianapolis, IN 46256

www.wiley.com

Copyright © 2006 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN-13: 978-0-7645-9723-7

ISBN-10: 0-7645-9723-X

Printed in the United States of America

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

1MA/RW/RR/QV/IN

Library of Congress Cataloging-in-Publication Data

Professional LAMP : Linux, Apache, MySQL, and PHP Web development / Jason Gerner ... [et al.].

p. cm.

ISBN-13: 978-0-7645-9723-7 (paper/website)

ISBN-10: 0-7645-9723-X (paper/website)

1. Web site development. 2. Open source software. I. Title: Linux, Apache, MySQL, and PHP Web development. II. Gerner,

Jason, 1978–

TK5105.888.P677 2006

005.2'762—dc22

2005026487

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 Section 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, Inc., 222 Rosewood Drive, Danvers,

MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal

Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355 or

online at http://www.wiley.com/go/permissions.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTA￾TIONS 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 PROMO￾TIONAL 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 REN￾DERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS

REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUB￾LISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGA￾NIZATION OR WEBSITE 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 INFORMA￾TION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER,

READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DIS￾APPEARED 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 (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, 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. Linux is a registered trademark of Linus Torvalds.

MySQL is a registered trademark of MySQL AB A Company. All other trademarks are the property of their respec￾tive 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.

01_59723x ffirs.qxd 10/31/05 6:37 PM Page iv

About the Authors

Jason Gerner currently spends his days working as a web developer in Cincinnati and burns free time

complaining about lack of support for web standards and abusing XML. He can often be found lurking

in the PHPBuilder.com discussion forums, where he is a moderator.

Elizabeth Naramore earned her B.S. in Organizational Behavior from Miami University (Ohio) and

has been developing websites since 1997. Her main focus has been on PHP/MySQL, e-commerce, and

freelance writing and teaching. Her writing can be seen in PHPBuilder.com and International PHP

Magazine. She is a proud member of OINK-PUG (Ohio, Indiana, Northern Kentucky PHP Users Group)

and she lives in Cincinnati, Ohio with her husband and two small children.

After graduating from the University of Auckland with a mathematics degree no one was interested in,

Morgan L. Owens knocked around the IT industry, becoming a backend web developer and program￾mer for web-based applications for both intranet and Internet environments. He still lives in Auckland

but suggests that for the right career he might—might—consider moving.

Matt Warden has been developing web-based applications for over six years. His work has primarily

focused on designing and implementing LAMP applications for other businesses to use internally to

increase productivity. Recently, Matt has been using AJAX to offer a web-based alternative to productiv￾ity gains typically only available with native desktop solutions. Currently, Matt is a lead developer at

Signal US Communications in Cincinnati, Ohio.

01_59723x ffirs.qxd 10/31/05 6:37 PM Page v

01_59723x ffirs.qxd 10/31/05 6:37 PM Page vi

Credits

Executive Editor

Carol Long

Senior Acquisitions Editor

Debra Williams Cauley

Development Editor

Brian MacDonald

Contributors

William Barnett

Wm. Christopher Mastin

Technical Editors

Jason Gerner

Elizabeth Naramore

Production Editor

Kenyon Brown

Copy Editor

Kathryn Duggan

Editorial Manager

Mary Beth Wakefield

Production Manager

Tim Tate

Vice President and Executive Group Publisher

Richard Swadley

Vice President and Executive Publisher

Joseph B. Wikert

Project Coordinator

Kristie Rees

Graphics and Production Specialists

Carrie Foster

Lauren Goddard

Denny Hager

Barbara Moore

Alicia B. South

Quality Control Technicians

Amanda Briggs

John Greenough

Jessica Kramer

Joe Niesen

Media Development Specialists

Angie Denny

Kate Jenkins

Steve Kudirka

Kit Malone

Travis Silvers

Media Development Coordinator

Laura Atkinson

Proofreading and Indexing

TECHBOOKS Production Services

01_59723x ffirs.qxd 10/31/05 6:37 PM Page vii

01_59723x ffirs.qxd 10/31/05 6:37 PM Page viii

Acknowledgments

Thanks to my lovely wife for putting up with me for the past few years, and being so supportive. I’d

also like to thank my co-authors for their great work and the time they spent working on this project.

Also, thanks to the folks at Wiley for giving us a chance, and big thanks to Brian for his huge help and

having faith in us.—Jason Gerner

I’d like to thank my parents, who always made me feel cool, even though I am and always will be a geek.

I’d also like to thank my husband and kids for taking care of me when I’m stressed out, and for being my

comic relief. Thanks also to Jason and Brian for bringing our book in for a landing.—Elizabeth Naramore

I would like to thank Scott and the rest of the crew from HIT Studios not least for introducing me to

this “PHP” thingy; my fellow authors for inviting me on this gig even after they saw my writing; Karl

Gustafson of the University of Colorado for a piece of advice years ago, though he no doubt has no idea

what I’m talking about; and my friends and family who really are a life support system—especially my

grandmother Doris Madeline Rachael Shipton (1918–2005).—Morgan L. Owens

Special thanks go to Sam Foster, who worked with me via email when we were initially trying to

determine best practices with XMLHTTP and XMLHttpRequest object use, during a time when there

was very little documentation on the subject. His ideas inspired many aspects of the design of the

RemoteConnection object.—Matt Warden

01_59723x ffirs.qxd 10/31/05 6:37 PM Page ix

01_59723x ffirs.qxd 10/31/05 6:37 PM Page x

Contents

Acknowledgments ix

Introduction xix

Chapter 1: What’s New in PHP5? 1

Object-Oriented Changes 1

Passing Objects 1

Exceptions 1

Interfaces 5

Iterators 5

Constructors and Destructors 6

Access Modifiers 6

The final Keyword 6

The static Keyword 7

The abstract Keyword 7

Built-In Method Overloading Functions 8

New Functions 9

Other Changes to PHP5 12

Configuration Changes 12

MySQLi 12

XML Support 16

Tidy Extension 17

SQLite 17

Summary 17

Chapter 2: PHP5 OOP 19

Procedural Programming versus OOP 19

Basic Class Definitions 20

Visibility 23

Constructors and Destructors 25

Static Keyword 27

Class Constants 28

Assignment versus Cloning 29

02_59723x ftoc.qxd 10/31/05 6:35 PM Page xi

xii

Contents

Inheritance and Interfaces 30

Inheritance 31

Interfaces 35

Magic Methods 37

__call 38

__get and __set 38

__sleep 39

__wakeup 40

__toString 43

Summary 45

Chapter 3: More Obscure PHP 47

Array Functions and Callbacks 48

Using Callbacks 48

array_map() 50

array_walk() 51

array_filter() and preg_grep() 53

preg_replace_callback() 53

call_user_func_array() and call_user_func() 55

create_function() 57

Final Observations on the Array Functions 59

glob() 60

PHP Streams 61

Creating and Using Streams 62

Two Examples of Streams 63

Summary 72

Chapter 4: Advanced MySQL 73

The Basics, Revisited 73

Creating the Databases 74

Adding Information 75

Retrieving Information 76

Updating Information 77

Removing Information 77

Querying Multiple Tables 77

Inner Joins 78

Outer Joins 81

Unions 82

02_59723x ftoc.qxd 10/31/05 6:35 PM Page xii

xiii

Contents

Full-Text Searching 86

Enabling Full-Text Searching 86

Querying Using Full-Text Search 87

Limitations 88

InnoDB Tables 88

InnoDB Advantages 88

InnoDB Disadvantages 89

Using InnoDB 89

Controlling Access 93

User Administration 93

Server Restriction 100

Analyzing the Database 100

SHOW COLUMNS 101

SHOW CREATE TABLE 101

SHOW DATABASES 102

SHOW GRANTS 102

Database Maintenance 103

Creating Backups 103

Restoring Databases from Backups 103

Summary 104

Chapter 5: PHP Configuration 105

Modifying php.ini 105

Recommended Configuration Directives 105

New to PHP5 107

PHP Configuration during Runtime 108

Obtaining Current Runtime Settings 108

Changing Configuration Dynamically 113

Automated Version and Feature Checking 116

Summary 128

Chapter 6: Apache Tricks 129

URL Rewriting 129

Enabling mod_rewrite 130

RewriteRule 131

RewriteCond 139

RewriteBase 143

RewriteLog 143

RewriteLogLevel 144

02_59723x ftoc.qxd 10/31/05 6:35 PM Page xiii

Tải ngay đi em, còn do dự, trời tối mất!