Shelving Category: COMPUTERS / Internet / Web Page Design Reader Level: Beginning to Advanced $49.99 USA $59.99 Canada Explore PHP syntax, datatypes, and functions Create database-driven, dynamic Web sites Master server-side Web programming Suehring, Converse, Park The book you need to succeed! Harness PHP and MySQL for robust Web development Start quickly building dynamic Web applications with the leading open-source scripting tool, the leading open-source database, and this comprehensive guide that shows you exactly how to do it. You’ll learn PHP6 and MySQL inside and out, explore the ups and downs of using open-source technologies, and discover pages of tips and techniques that help you get the most out of this powerful development duo. is book includes extensive code examples, full working applications, and much more. • Install, develop, debug, and troubleshoot the newest versions of PHP and MySQL • Get up to speed on PHP basics, including syntax, datatypes, functions, and pitfalls • Review Structured Query Language (SQL) and data administration basics • Master advanced PHP features, including object-oriented programming and session handling • Examine PHP’s interaction with other databases technologies, such as Oracle ® • Explore advanced topics, such as PHP with e-mail programs, and PHP and XML • Learn how to create a game and much more in extended case studies PHP6 and MySQL ® Steve Suehring is a technology consultant with a diverse business and computing background. He is the former security editor for LinuxWorld Magazine and has published several books. Tim Converse is a software engineer at Inktomi Corporation, which is owned by Yahoo!. He has more than a dozen years of programming experience in Lisp, C, C++, Java, and Web techniques, including PHP. Joyce Park is a Web developer in Silicon Valley. She has worked on PHP projects of all sizes, including co-lead of the Mod-pulsub project. Spine: 1.824" Steve Suehring, Tim Converse, and Joyce Park PHP6 and MySQL ® www.it-ebooks.info 84503ffirs.indd 2 12/16/08 1:09:21 PM www.it-ebooks.info PHP 6 and MySQL ® 6 Bible 84503ffirs.indd 1 12/16/08 1:09:21 PM www.it-ebooks.info 84503ffirs.indd 2 12/16/08 1:09:21 PM www.it-ebooks.info Steve Suehring Tim Converse Joyce Park PHP 6 and MySQL ® 6 Bible 84503ffirs.indd 3 12/16/08 1:09:22 PM www.it-ebooks.info PHP 6 and MySQL 6 Bible Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-38450-3 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 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. Library of Congress Cataloging-in-Publication Data Suehring, Steve. PHP 6 and MySQL 6 bible / Steve Suehring. p. cm. Includes index. ISBN 978-0-470-38450-3 (pbk.) 1. PHP (Computer program language) 2. MySQL (Electronic resource) I. Title. QA76.73.P224S94 2009 005.2’762 — dc22 2008048198 Trademarks: Wiley and the Wiley logo 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 in the United States, European Union, and other countries. 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. 84503ffirs.indd 4 12/16/08 1:09:22 PM www.it-ebooks.info About the Authors Steve Suehring is a technology consultant with a diverse business and computing background. Steve’s extensive experience enables him to work cross-functionally within organizations to help create computing architectures that fit the business need. Steve has written several books and mag- azine articles and contributed to many others. Steve has spoken internationally at user groups and conventions. When he has the chance, Steve plays just about any sport or any musical instrument, some with better success than others. Tim Converse has written software to recommend neckties, answer questions about space sta- tions, pick value stocks, and make simulated breakfast. He has an M.S. in Computer Science from the University of Chicago, where he taught several programming classes. He is now an engineering manager in the Web search group at Yahoo!. Joyce Park has an M.A. in history from the University of Chicago, and has worked for several Silicon Valley startups including Epinions, KnowNow, and Friendster. She is a co-lead of the Mod-pubsub Open Source project. 84503ffirs.indd 5 12/16/08 1:09:22 PM www.it-ebooks.info Acquisitions Editor Jenny Watson Development Editor Christopher J. Rivera Technical Editor Aaron Saray Production Editor Rachel McConlogue Copy Editor Foxxe Editorial Services Editorial Manager Mary Beth Wakefield Production Manager Tim Tate Vice President and Executive Group Publisher Richard Swadley Vice President and Executive Publisher Barry Pruett Associate Publisher Jim Minatel Project Coordinator, Cover Lynsey Stanford Compositor Jeffrey Wilson, Happenstance Type-O-Rama Proofreader Publication Services, Inc. Indexer Ted Laux Cover Illustration Joyce Haughey Cover Designer Michael E. Trent Credits 84503ffirs.indd 6 12/16/08 1:09:23 PM www.it-ebooks.info Acknowledgments People sometimes ask me how many books I’ve written. I never have the answer. You see, I’ve con- tributed to well over a dozen (maybe two dozen or more) books in one form or another, be it a chap- ter or two here, a section there, a rewrite of an existing title with much new material, a revision of another edition where the existing material is already pretty good (as was the case for this book), or an original, authored work. The short answer is: I don’t know. It’s really somewhat difficult to claim that I, alone, wrote a book. At best I put some words down into a word processor and several other people look them over, edit them, change them for both technical and grammatical usage, and the end result is my name on the cover or somewhere in the book, or sometimes not at all. This brings me to the difficulty at hand. I’ve written a sufficient number books that writing acknowledgments is becoming a bit mundane. Sure, I’ll thank my wife, Rebecca, and son, Jakob, for their patience while I wrote this. I’ll thank my family for their continued support. I’ll thank the Tueschers, Heins, Leus, and Guthries. I’ll thank Jason Keup and Aaron Saray, too. I’ll thank my agent Neil Salkind at Studio B., Jim Oliva and John Eckendorf, and the 90fm staff along with Nightmare Squad. Of course, I’ll thank Tim and Rob @ Partners, and Jay, Deb, and Brian, and Andy Hale and Eliot Irons and the SecAdmin team. Kyle Mac always gets mad if I don’t include him. There are lot of people at Knob Hill who deserve thanking, and the like. And I’ll always thank Mark Little and meek, Pat Dunn, AJ Prowant, and Andy Berkvam. But it’s the people that I don’t thank that always find me, asking why their name isn’t in this book. With that in mind, I’ll stop here and let them find me and hope that I write another book where I’ll remember to include them. Just a hint: Everyone who was thanked here has paid me. 84503ffirs.indd 7 12/16/08 1:09:23 PM www.it-ebooks.info 84503ffirs.indd 8 12/16/08 1:09:23 PM www.it-ebooks.info [...]... .65 6 Using DOM XML 65 7 DOM functions 65 7 xxix www.it-ebooks.info 84503ftoc.indd 29 12/ 16/ 08 1:09: 46 PM Contents SAX 65 9 Using SAX .66 0 SAX options 66 1 SAX functions 66 3 SimpleXML API .66 4 Using SimpleXML 66 4 SimpleXML functions 66 5 A Sample XML Application .66 5 Gotchas and. .. 62 0 Packages and libraries 62 0 Differences 62 0 Compiled versus scripting 62 1 Variable declaration and loose typing 62 1 Java Server Pages and PHP 62 1 Embedded HTML 62 1 Choose your scripting language 62 2 Integrating PHP and Java .62 2 The Java SAPI 62 3 Installation and setup 62 3 Further information... with PHP 61 3 Chapter 38: Integrating PHP and Java 61 9 Chapter 39: Integrating PHP and JavaScript 63 1 Chapter 40: Integrating PHP and XML .64 7 Chapter 41: Creating and Consuming Web Services with PHP 67 5 Chapter 42: Creating Graphics with PHP 68 9 Part VI: Case Studies 713 Chapter 43: Developing a Weblog with PHP. .. 62 9 Chapter 39: Integrating PHP and JavaScript. 63 1 Outputting JavaScript with PHP 63 1 Dueling objects 63 2 PHP doesn’t care what it outputs 63 2 Where to use JavaScript 63 3 PHP as a Backup for JavaScript 63 4 Static versus Dynamic JavaScript 63 6 Dynamically generated forms 63 7... data back to PHP from JavaScript .64 2 Summary 64 6 Chapter 40: Integrating PHP and XML. 64 7 What Is XML? 64 7 Working with XML 65 0 Documents and DTDs 65 1 The structure of a DTD 65 3 Validating and nonvalidating parsers 65 5 SAX versus DOM 65 5 DOM ... 61 6 Summary 61 8 Chapter 38: Integrating PHP and Java 61 9 PHP for Java programmers 61 9 Similarities 62 0 Syntax 62 0 Operators .62 0 Object model .62 0 xxviii www.it-ebooks.info 84503ftoc.indd 28 12/ 16/ 08 1:09: 46 PM Contents Memory management 62 0 Packages... 68 1 Potentially heavy load 68 1 Standards 68 2 Hide and seek 68 2 Who pays and how? .68 2 Project: A REST Client 68 3 Summary 68 8 Chapter 42: Creating Graphics with PHP. 68 9 Your Options 68 9 HTML Graphics 69 0 Creating images using gd 69 5... .732 index .php 732 game_display_class .php 735 game_text_class .php 744 game_class .php 7 46 game_parameters_class .php 753 certainty_utils .php 755 question_class .php 759 dbvars .php 763 Creating the database 764 Table definitions 764 entry_form .php 766 General Design Considerations... .62 3 The Java extension 62 3 Installation and setup 62 4 Testing 62 5 The Java object 62 5 Errors and exceptions 62 7 Potential gotchas 62 8 Installation problems 62 8 It’s the classpath, stupid .62 8 Here comes that loose typing again .62 8 Speed 62 8 The sky’s the limit 62 9 Summary... Creating images using gd 69 5 What is gd? 69 5 Image formats and browsers 69 6 Installation 69 6 gd Concepts 69 7 Colors 69 8 Drawing coordinates and commands 69 9 Format translation .69 9 Freeing resources 69 9 Functions 700 Images and HTTP 701 Full-page images 701 Embedded . 2 12/ 16/ 08 1:09:21 PM www.it-ebooks.info Steve Suehring Tim Converse Joyce Park PHP 6 and MySQL ® 6 Bible 84503ffirs.indd 3 12/ 16/ 08 1:09:22 PM www.it-ebooks.info PHP 6 and MySQL 6 Bible Published. Suehring, Tim Converse, and Joyce Park PHP6 and MySQL ® www.it-ebooks.info 84503ffirs.indd 2 12/ 16/ 08 1:09:21 PM www.it-ebooks.info PHP 6 and MySQL ® 6 Bible 84503ffirs.indd 1 12/ 16/ 08 1:09:21 PM www.it-ebooks.info 84503ffirs.indd. with PHP 61 3 Chapter 38: Integrating PHP and Java 61 9 Chapter 39: Integrating PHP and JavaScript 63 1 Chapter 40: Integrating PHP and XML 64 7 Chapter 41: Creating and Consuming Web Services with PHP