ebook img

PHP And MySQL Web Development PDF

984 Pages·2005·10.528 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview PHP And MySQL Web Development

00 6728 fm 9/2/04 1:15 PM Page i “I’ve never purchased a better “I picked up this book two days ago programming book… This book proved to and I am half way finished.I just can’t put be the most informative,easiest to follow, it down.The layout and flow is perfect. and had the best examples of any other Everything is presented in such a way so computer-related book I have ever that the information is very palatable.I am purchased.The text is very easy to follow!” able to immediately grasp all the concepts. The examples have also been wonderful. —Nick Landman I just had to take some time out to express to you how pleased I have been with “…the Sams book by Welling & this book.” Thomson is the only one which I have found to be indispensable.The writing is —Jason B.Lancaster clear and straightforward but never wastes my time.The book is extremely well laid “This book has proven a trusty out.The chapters are the right length and companion,with an excellent crash course chapter titles quickly take you where you in PHP and superb coverage of MySQL as want to go.” used for Web applications.It also features several complete applications that are great —Wright Sullivan,President,A&E Engineering,Inc.,Greer South Carolina examples of how to construct modular, scalable applications with PHP.Whether “I just wanted to tell you that I think the you are a PHP newbie or a veteran in book PHP and MySQL Web Development search of a better desk-side reference,this rocks! It’s logically structured,just the right one is sure to please!” difficulty level for me (intermediate), —WebDynamic interesting and easy to read,and,of course, full of valuable information!” “The true PHP/MySQL bible,PHP —CodE-E,Austria and MySQL Web Developmentby Luke Welling and Laura Thomson,made me “There are several good introductory realize that programming and databases are books on PHP,but Welling & Thomson is an now available to the commoners.Again,I excellent handbook for those who wish to know 1/10000th of what there is to know, build up complex and reliable systems.It’s and already I’m enthralled.” obvious that the authors have a strong back- —Tim Luoma,TnTLuoma.com ground in the development of professional applications and they teach not only “Welling and Thomson’s book is a good the language itself,but also how to use it reference for those who want to get to with good software engineering practices.” grips with practical projects straight off the —Javier Garcia,senior telecom engineer, bat.It includes webmail,shopping cart, Telefonica R&D Labs,Madrid session control,and web-forum/weblog applications as a matter of course,and begins with a sturdy look at PHP first, moving to MySQL once the basics are covered.” —twilight30 on Slashdot 00 6728 fm 9/2/04 1:15 PM Page ii “This book is absolutely excellent,to “This is a well-written book for learn- say the least….Luke Welling and Laura ing how to build Internet applications with Thomson give the best in-depth explana- two of the most popular open-source Web tions I’ve come across on such things as development technologies….The projects regular expressions,classes and objects, are the real jewel of the book.Not only are sessions etc.I really feel this book filled in a the projects described and constructed in a lot of gaps for me with things I didn’t quite logical,component-based manner,but the understand….This book jumps right into selection of projects represents an excellent the functions and features most commonly cross-section of common components that used with PHP,and from there it continues are built into many web sites.” in describing real-world projects,MySQL —Craig Cecil integration,and security issues from a proj- ect manager’s point of view.I found every “The book takes an easy,step-by-step bit of this book to be well organized and approach to introduce even the clueless easy to understand.” programmer to the language of PHP.On —notepad on codewalkers.com top of that,I often find myself referring back to it in my Web design efforts.I’m still “A top-notch reference for learning new things about PHP,but this programmers using PHP and MySQL. book gave me a solid foundation from Highly recommended.” which to start and continues to help me to this day.” —The Internet Writing Journal —Stephen Ward “This book rocks! I am an experienced programmer,so I didn’t need a lot of help “This book is one of few that really with PHP syntax;after all,it’s very close to touched me and made me ‘love’it.I can’t C/C++.I don’t know a thing about put it in my bookshelf;I must put it in a databases,though,so when I wanted to touchable place on my working bench as I develop a book review engine (among always like to refer from it.Its structure is other projects) I wanted a solid reference good,wordings are simple and straight for- to using MySQL with PHP.I have ward,and examples are clear and step by O’Reilly’s mSQL and MySQLbook,and step.Before I read it,I knew nothing of it’s probably a better pure-SQL reference, PHP and MySQL.After reading it,I have but this book has earned a place on my the confidence and skill to develop any reference shelf…Highly recommended.” complicated Web application.” —Paul Robichaux —Power Wong “One of the best programming guides “This book is God….I highly recom- I’ve ever read.” mend this book to anyone who wants to jump in the deep end with database driven —jackofsometrades from Lahti,Finland Web application programming.I wish more computer books were organized this way.” —Sean C Schertell 00 6728 fm 9/2/04 1:15 PM Page iii PHP and MySQL Web Development Third Edition Luke Welling Laura Thomson DEVELOPER’S LIBRARY Sams Publishing,800 East 96th Street,Indianapolis,Indiana 46240 00 6728 fm 9/2/04 1:15 PM Page iv PHP and MySQL Web Development Acquisitions Editor Third Edition Shelley Johnston Copyright 2005 by Sams Publishing Development Editor Scott Meyers All rights reserved.No part of this book shall be reproduced,stored in a retrieval system,or transmitted by any means,electronic,mechanical,photo- Managing Editor copying,recording,or otherwise,without written permission from the pub- Charlotte Clapp lisher.No patent liability is assumed with respect to the use of the informa- Copy Editor tion contained herein.Although every precaution has been taken in the Chuck Hutchinson preparation of this book,the publisher and authors assume no responsibility for errors or omissions.Neither is any liability assumed for damages resulting Indexer from the use of the information contained herein. Mandie Frank International Standard Book Number:0-672-32672-8 Proofreader Library of Congress Catalog Card Number:2003099244 Paula Lowell Printed in the United States of America Technical Editors First Printing:October 2004 Sara Golemon 07 06 05 04 4 3 2 1 Chris Newman Media Specialist Trademarks Dan Scherf All terms mentioned in this book that are known to be trademarks or service Design marks have been appropriately capitalized.Sams Publishing cannot attest to Gary Adair 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. Page Layout Cheryl Lynch Warning and Disclaimer Michelle Mitchell 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 arising from the information contained in this book or from the use of the CD-ROM 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 [email protected] For sales outside the U.S.,please contact International Sales 1-317-428-3341 [email protected] 00 6728 fm 9/2/04 1:15 PM Page v ❖ To our Mums and Dads ❖ 00 6728 fm 9/2/04 1:15 PM Page vi Contents at a Glance Introduction 1 I Using PHP 1 PHP Crash Course 11 2 Storing and Retrieving Data 57 3 Using Arrays 79 4 String Manipulation and Regular Expressions 105 5 Reusing Code and Writing Functions 129 6 Object-Oriented PHP 157 7 Exception Handling 191 II Using MySQL 8 Designing Your Web Database 205 9 Creating Your Web Database 217 10 Working with Your MySQL Database 241 11 Accessing Your MySQL Database from the Web with PHP 265 12 Advanced MySQL Administration 285 13 Advanced MySQL Programming 307 III E-commerce and Security 14 Running an E-commerce Site 323 15 E-commerce Security Issues 337 16 Implementing Authentication with PHP and MySQL 357 17 Implementing Secure Transactions with PHP and MySQL 379 00 6728 fm 9/2/04 1:15 PM Page vii IV Advanced PHP Techniques 18 Interacting with the File System and the Server 401 19 Using Network and Protocol Functions 419 20 Managing the Date and Time 439 21 Generating Images 451 22 Using Session Control in PHP 479 23 Other Useful Features 495 V Building Practical PHP and MySQL Projects 24 Using PHP and MySQL for Large Projects 507 25 Debugging 523 26 Building User Authentication and Personalization 541 27 Building a Shopping Cart 579 28 Building a Content Management System 625 29 Building a Web-Based Email Service 657 30 Building a Mailing List Manager 695 31 Building Web Forums 751 32 Generating Personalized Documents in Portable Document Format (PDF) 783 33 Connecting to Web Services with XML and SOAP 819 VI Appendixes A Installing PHP and MySQL 867 B Web Resources 889 Index 893 00 6728 fm 9/2/04 1:15 PM Page viii Table of Contents Introduction 1 I Using PHP 1 PHP Crash Course 11 Using PHP 12 Creating a Sample Application:Bob’s Auto Parts 12 Creating the Order Form 12 Processing the Form 14 Embedding PHP in HTML 15 Use of PHP Tags 16 PHP Tag Styles 16 PHP Statements 17 Whitespace 18 Comments 18 Adding Dynamic Content 19 Calling Functions 20 Using the date() Function 20 Accessing Form Variables 21 Form Variables 21 String Concatenation 24 Variables and Literals 25 Understanding Identifiers 26 Creating User-Declared Variables 26 Assigning Values to Variables 26 Examining Variable Types 27 PHP’s Data Types 27 Type Strength 27 Type Casting 28 Variable Variables 28 Declaring and Using Constants 29 Understanding Variable Scope 29 00 6728 fm 9/2/04 1:15 PM Page ix Using Operators 30 Arithmetic Operators 31 String Operators 32 Assignment Operators 32 Comparison Operators 34 Logical Operators 36 Bitwise Operators 36 Other Operators 37 Using Operators:Working Out the Form Totals 39 Understanding Precedence and Associativity: Evaluating Expressions 40 Using Variable Functions 42 Testing and Setting Variable Types 42 Testing Variable Status 43 Reinterpreting Variables 44 Implementing Control Structures 44 Making Decisions with Conditionals 44 if Statements 44 Code Blocks 45 else Statements 45 elseif Statements 46 switch Statements 47 Comparing the Different Conditionals 49 Repeating Actions Through Iteration 49 while Loops 51 for and foreach Loops 52 do..while Loops 53 Breaking Out of a Control Structure or Script 54 Employing Alternative Control Structure Syntax 54 Using declare 55 Next:Saving the Customer’s Order 55 2 Storing and Retrieving Data 57 Saving Data for Later 57 Storing and Retrieving Bob’s Orders 58 Processing Files 59 00 6728 fm 9/2/04 1:15 PM Page x x Contents Opening a File 59 Choosing File Modes 59 Using fopen() to Open a File 60 Opening Files Through FTP or HTTP 62 Addressing Problems Opening Files 63 Writing to a File 65 Parameters for fwrite() 66 File Formats 66 Closing a File 67 Reading from a File 69 Opening a File for Reading:fopen() 70 Knowing When to Stop:feof() 71 Reading a Line at a Time:fgets(),fgetss(), and fgetcsv() 71 Reading the Whole File:readfile(), fpassthru(),and file() 72 Reading a Character:fgetc() 73 Reading an Arbitrary Length:fread() 73 Using Other Useful File Functions 74 Checking Whether a File Is There: file_exists() 74 Determining How Big a File Is:filesize() 74 Deleting a File:unlink() 74 Navigating Inside a File:rewind(),fseek(), and ftell() 74 Locking Files 76 Doing It a Better Way:Database Management Systems 77 Problems with Using Flat Files 77 How RDBMSs Solve These Problems 78 Further Reading 78 Next 78 3 Using Arrays 79 What Is an Array? 79 Numerically Indexed Arrays 80 Initializing Numerically Indexed Arrays 80 Accessing Array Contents 81 Using Loops to Access the Array 82

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.