PHP and Mysql PHP and Mysql
Total Page:16
File Type:pdf, Size:1020Kb
Wandschneider.book Page i Tuesday, August 5, 2008 2:14 PM PHP and MySQL Marc Wandschneider Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City Wandschneider.book Page ii Tuesday, August 5, 2008 2:14 PM Copyright © 2009 Pearson Education, Inc. Publisher All rights reserved. Printed in the United States of America. This publication is Paul Boger protected by copyright, and permission must be obtained from the publisher prior to any Editor-in-Chief prohibited reproduction, storage in a retrieval system, or transmission in any form or by Mark L. Taub any means, electronic, mechanical, photocopying, recording, or likewise. No part of this LiveLessons book or DVD set may be reproduced or transmitted in any form or by any Video Project Manager means, electronic or mechanical, including photocopying, recording, or by any John A. Herrin information storage and retrieval system, without written permission from the publisher, except for the inclusion of brief quotations in a review. Editorial Assistant Kim Boedigheimer For information regarding permissions, write to: Pearson Education, Inc., Rights and Contracts Department, 501 Boylston Street, Suite 900, Boston, MA 02116, Fax (617) Managing Editor 671-3447. John Fuller Library of Congress Control Number: 2008933546 Project Editor Visit us on the Web: informit.com/ph Julie B. Nahil Corporate and Government Sales Copy Editor The publisher offers excellent discounts on this LiveLesson when ordered in quantity for Ruth Davis bulk purchases or special sales, which may include custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more Proofreader information, please contact: U.S. Corporate and Government Sales, (800) 382-3419, Julie Lonergan [email protected]. Multimedia Developer For sales outside the United States, please contact: International Sales, Eric Strom, Pearson Video [email protected]. Production Services Warning and Disclaimer Designer This book and video product is designed to provide information about PHP and MySQL Gary Adair programming. Every effort has been made to make it as complete and as accurate as possible, but no warranty or fitness is implied. The information is provided on an “as is” basis. The author and Pearson 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 disc or programs that may accompany it. The opinions expressed in this LiveLesson belong to the author and are not necessarily those of Pearson. Feedback Information At Pearson, our goal is to create in-depth technical products of the highest quality and value. Each product is crafted with care and precision, undergoing rigorous development that involves the unique expertise of members from the professional technical community. Readers’ feedback is a natural continuation of this process. If you have any comments regarding how we could improve the quality of this LiveLesson, or otherwise alter it to better suit your needs, you can contact us through e-mail at [email protected]. Please make sure to include the title and ISBN in your message. We greatly appreciate your assistance. Trademark Acknowledgments All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Neither Prentice Hall nor Pearson Education, Inc., can attest to 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. ISBN-13: 978-0-13-715575-0 ISBN-10: 0-13-715575-1 Text printed in the United States at RR Donnelley in Crawfordsville, Indiana. First printing, September 2008 Wandschneider.book Page iii Tuesday, August 5, 2008 2:14 PM Contents Lesson 1 Installation of MySQL, Apache, and PHP........................................................1 Windows................................................................................................................ 1 MySQL .............................................................................................................. 1 Apache HTTPD Server...................................................................................... 1 PHP ................................................................................................................... 2 Mac / Unix ............................................................................................................. 2 Xcode................................................................................................................ 2 MySQL .............................................................................................................. 2 Apache HTTP Server ........................................................................................ 2 PHP ................................................................................................................... 4 Starting and Stopping the Servers ................................................................... 5 Troubleshooting................................................................................................ 5 Lesson 2 Your First Web Application ............................................................................7 Getting Started ..................................................................................................... 7 Entering PHP Scripts ............................................................................................. 8 Marking Sections of PHP Code ........................................................................ 8 Mixing PHP and HTML ..................................................................................... 9 Statements and Comments............................................................................ 10 Variables .............................................................................................................. 11 Numbers ......................................................................................................... 11 Strings............................................................................................................. 12 Booleans ......................................................................................................... 13 Working with Multiple Pages .............................................................................. 13 Lesson 3 Language Basics...........................................................................................15 Arrays .................................................................................................................. 15 Testing Variables.................................................................................................. 15 Simple Variable Substitution ............................................................................... 16 Arithmetic Operators .......................................................................................... 16 Type Conversions ................................................................................................ 17 NULL.................................................................................................................... 18 The if Statement.................................................................................................. 18 Comparison Operators: Equality and Identity .................................................... 18 iii Wandschneider.book Page iv Tuesday, August 5, 2008 2:14 PM iv Contents Lesson 4 More Language Features .............................................................................21 Script Lifetime..................................................................................................... 21 Strings, Newlines, and the Web Browser............................................................ 21 Constants ............................................................................................................ 22 More Comparison Operators.............................................................................. 22 Logical Operators ............................................................................................... 22 The switch Statement ......................................................................................... 23 Lesson 5 Functions and Loops ....................................................................................25 Loops .................................................................................................................. 25 while loop....................................................................................................... 25 Functions............................................................................................................. 26 Byval and Byref Parameters ................................................................................ 27 Scoping ............................................................................................................... 28 Lesson 6 Text and Strings ...........................................................................................29 Review of Strings in PHP..................................................................................... 29 More on Variable Expansion ..............................................................................