beginning php and postgresql 8

863 1.3K 0
beginning php and postgresql 8

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info Beginning PHP and PostgreSQL 8 From Novice to Professional ■■■ W. Jason Gilmore and Robert H. Treat www.it-ebooks.info Beginning PHP and PostgreSQL 8: From Novice to Professional Copyright © 2006 by W. Jason Gilmore All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-547-3 ISBN-10 (pbk): 1-59059-547-5 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Matthew Moodie Technical Reviewers: Greg Sabino Mullane, Matt Wade Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Matt Wade Project Manager: Beth Christmas Copy Edit Manager: Nicole LeClerc Copy Editor: Bill McManus Assistant Production Director: Kari Brooks-Copony Production Editor: Laura Cheu Compositor: Susan Glinert Stevens Proofreader: Nancy Sixsmith Indexer: John Collin Artist: Kinetic Publishing Services, LLC Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code section. www.it-ebooks.info This book is dedicated to the memory of my grandfather, William J. Gilmore, for introducing me to the world of computers. —W. Jason Gilmore I dedicate this book to my mother, Gladys Emilia Treat. Puedes vivir solo una vez, pero si lo haces bien, una vez es suficiente. —Robert H. Treat www.it-ebooks.info v Contents at a Glance About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv About the Technical Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi ■CHAPTER 1 An Introduction to PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 ■CHAPTER 2 Installing and Configuring Apache and PHP . . . . . . . . . . . . . . . . . . . . 9 ■CHAPTER 3 PHP Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 ■CHAPTER 4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 ■CHAPTER 5 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 ■CHAPTER 6 Object-Oriented PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 ■CHAPTER 7 Advanced OOP Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 ■CHAPTER 8 Error and Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 ■CHAPTER 9 Strings and Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 ■CHAPTER 10 Working with the File and Operating System . . . . . . . . . . . . . . . . . 229 ■CHAPTER 11 PEAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 ■CHAPTER 12 Date and Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 ■CHAPTER 13 Forms and Navigational Cues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 ■CHAPTER 14 Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 ■CHAPTER 15 Handling File Uploads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 ■CHAPTER 16 Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 ■CHAPTER 17 PHP and LDAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 ■CHAPTER 18 Session Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 ■CHAPTER 19 Templating with Smarty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 ■CHAPTER 20 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473 ■CHAPTER 21 Secure PHP Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515 ■CHAPTER 22 SQLite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535 www.it-ebooks.info vi ■CHAPTER 23 Introducing PDO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555 ■CHAPTER 24 Introducing PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573 ■CHAPTER 25 Installing PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579 ■CHAPTER 26 PostgreSQL Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 ■CHAPTER 27 The Many PostgreSQL Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611 ■CHAPTER 28 From Databases to Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625 ■CHAPTER 29 Securing PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649 ■CHAPTER 30 PHP’s PostgreSQL Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665 ■CHAPTER 31 Practical Database Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689 ■CHAPTER 32 Views and Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707 ■CHAPTER 33 PostgreSQL Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719 ■CHAPTER 34 PostgreSQL Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739 ■CHAPTER 35 Indexes and Searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 749 ■CHAPTER 36 Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765 ■CHAPTER 37 Importing and Exporting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777 ■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 787 www.it-ebooks.info vii Contents About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv About the Technical Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi ■CHAPTER 1 An Introduction to PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 PHP 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 PHP 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 General Language Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Practicality. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Possibility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 ■CHAPTER 2 Installing and Configuring Apache and PHP . . . . . . . . . . . . . . 9 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Obtaining the Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 The Installation Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Testing Your Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Customizing the Unix Build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Customizing the Windows Build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Common Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Viewing and Downloading the Documentation . . . . . . . . . . . . . . . . . 18 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Managing PHP’s Configuration Directives . . . . . . . . . . . . . . . . . . . . . 19 PHP’s Configuration Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Contents www.it-ebooks.info viii ■CONTENTS ■CHAPTER 3 PHP Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Escaping to PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Default Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Short-Tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 ASP-Style. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Embedding Multiple Code Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Single-line C++ Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Shell Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Multiple-Line C Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 print() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 echo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 printf(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 sprintf(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Scalar Datatypes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Compound Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Special Datatypes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Type Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Type Juggling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Type-Related Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Type Identifier Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Variable Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 PHP’s Superglobal Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Variable Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 String Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Double Quotes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Single Quotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Heredoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 www.it-ebooks.info ■CONTENTS ix Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Execution Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Looping Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 File Inclusion Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 ■CHAPTER 4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Invoking a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Creating a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Passing Arguments by Value. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Passing Arguments by Reference. . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Default Argument Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Optional Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Returning Values from a Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Nesting Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Recursive Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Variable Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Function Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 ■CHAPTER 5 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 What Is an Array? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Outputting Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Creating an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Testing for an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Adding and Removing Array Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Locating Array Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Traversing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Determining Array Size and Uniqueness . . . . . . . . . . . . . . . . . . . . . . . . . 116 Sorting Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Merging, Slicing, Splicing, and Dissecting Arrays . . . . . . . . . . . . . . . . . . 124 Other Useful Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 www.it-ebooks.info x ■CONTENTS ■CHAPTER 6 Object-Oriented PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 The Benefits of OOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Key OOP Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 __set() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Type Hinting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Constructors and Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Static Class Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 The instanceof Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Helper Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Autoloading Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 ■CHAPTER 7 Advanced OOP Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Advanced OOP Features Not Supported by PHP . . . . . . . . . . . . . . . . . . . 157 Object Cloning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Cloning Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 The __clone() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Class Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Inheritance and Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Implementing a Single Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Implementing Multiple Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 www.it-ebooks.info [...]... 581 Installing PostgreSQL on Linux and Unix 582 Installing PostgreSQL on Windows 2000, XP, and 2003 585 Installing PostgreSQL on Windows 95, 98, and ME 589 Starting PostgreSQL for the First Time 589 Summary 591 ■CHAPTER 26 PostgreSQL Administration ... together, PHP and PostgreSQL offer users an impressive platform for building high-powered Web applications This book shows you how Beginning PHP and PostgreSQL 8: From Novice to Professional helps you sort the substantive from the superfluous to begin creating PHP- and PostgreSQL- driven Web applications as quickly as possible Based on the structure and material found in the bestselling title Beginning PHP. .. ■CHAPTER 8 Error and Exception Handling 177 Configuration Directives 177 Error Logging 180 Exception Handling 183 Why Exception Handling Is Handy 183 PHP s Exception-Handling Implementation 185 Summary... ■CHAPTER 37 Importing and Exporting Data 777 The COPY Command 777 Copying Data to and from a Table 7 78 Calling COPY from a PHP Script 782 Importing and Exporting Data with phpPgAdmin 783 Summary 785 ■INDEX ... mailing lists and Web sites, has spoken twice at OSCon on PostgreSQL topics, and has contributed code to the PostgreSQL core He is the primary developer of the DBD::Pg module, and has been recognized as a PostgreSQL Major Developer for all of PostgreSQL work He has a strong interest in PGP and cryptography, and attends keysignings as often as possible His PGP fingerprint is 2529 DF6A B8F7 9407 E944... 6 78 Retrieving and Displaying Data 6 78 Rows Selected and Rows Affected 681 Inserting, Modifying, and Deleting Data 682 Inserting Data 682 Mass Inserts 683 Modifying Data 684 Deleting... of a better understanding of both the software’s behaviors and quirks So grab a snack and cozy up to your keyboard; it’s time to build www.it-ebooks.info 7 CHAPTER 2 ■■■ Installing and Configuring Apache and PHP I n this chapter, you’ll learn how to install and configure PHP, and in the process learn how to install the Apache Web server If you don’t already have a working Apache /PHP server at your... 2529 DF6A B8F7 9407 E944 45B4 BC9B 9067 1496 4AC8, and he has been known to sneak it into code he has written He currently works as a software developer for End Point, primarily doing PostgreSQL, Perl, and PHP work He and his wife Joy enjoy traveling, and try to make at least one overseas trip a year ■ MATT WADE is a database analyst by day and a freelance PHP developer by night He has extensive experience... Displaying the Localized Date and Time 279 Displaying the Web Page’s Most Recent Modification Date 283 Determining the Number Days in the Current Month 283 Calculating the Date X Days from the Present Date 284 Creating a Calendar 285 PHP 5.1 288 Date Fundamentals ... user, developer, and advocate He has worked with a number of projects but his favorite is certainly PostgreSQL His current involvement includes helping maintain the postgresql. org Web sites, working on phpPgAdmin, and contributing to the PostgreSQL core whenever he can He has contributed several articles to the PostgreSQL “techdocs” site, presented multiple times at OSCon, worked as the PHP Foundry Admin . www.it-ebooks.info Beginning PHP and PostgreSQL 8 From Novice to Professional ■■■ W. Jason Gilmore and Robert H. Treat www.it-ebooks.info Beginning PHP and PostgreSQL 8: From Novice to Professional Copyright. . . . . 581 Installing PostgreSQL on Linux and Unix . . . . . . . . . . . . . . . . . . . . . 582 Installing PostgreSQL on Windows 2000, XP, and 2003 . . . . . . . . 585 Installing PostgreSQL. . . . . . . . . . . . . . 180 Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Why Exception Handling Is Handy. . . . . . . . . . .

Ngày đăng: 24/04/2014, 14:41

Mục lục

  • About the Technical Reviewers

  • CHAPTER 1: An Introduction to PHP

    • History

      • PHP 4

      • CHAPTER 2: Installing and Configuring Apache and PHP

        • Installation

          • Obtaining the Distributions

          • Customizing the Unix Build

          • Customizing the Windows Build

          • Viewing and Downloading the Documentation

          • Configuration

            • Managing PHP's Configuration Directives

            • PHP's Configuration Directives

            • CHAPTER 3: PHP Basics

              • Escaping to PHP

                • Default Syntax

                • Embedding Multiple Code Blocks

                • PHP's Superglobal Variables

                • Control Structures

                  • Execution Control Statements

                  • CHAPTER 4: Functions

                    • Invoking a Function

                    • Creating a Function

                      • Passing Arguments by Value

                      • Passing Arguments by Reference

                      • Returning Values from a Function

                      • CHAPTER 5: Arrays

                        • What Is an Array?

                        • Testing for an Array

                        • Adding and Removing Array Elements

                        • Determining Array Size and Uniqueness

Tài liệu cùng người dùng

Tài liệu liên quan