Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


PHP Y MYSQL, Apuntes de Ingeniería Aeronáutica

Asignatura: Sistema de gestio de dades, Profesor: , Carrera: Gestió Aeronàutica, Universidad: UAB

Tipo: Apuntes

Antes del 2010

Subido el 21/07/2008

garlak
garlak 🇪🇸

4.1

(40)

33 documentos

1 / 459

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Vista previa parcial del texto

¡Descarga PHP Y MYSQL y más Apuntes en PDF de Ingeniería Aeronáutica solo en Docsity!

PHP & MySQL

FOR

DUMmIES

2 ND EDITION

by Janet Valade

PHP & MySQL

FOR

DUMmIES

2 ND EDITION

PHP & MySQL ^ For Dummies®, 2nd Edition Published by Wiley Publishing, Inc. 111 River Street Hoboken, NJ 07030-

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

Published by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

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 permit ted 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 Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, e-mail: [email protected].

Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, 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. 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.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REP RESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CON TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CRE ATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CON TAINED 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 WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FUR THER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFOR MATION 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 DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.

For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at 800-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Control Number: 2004101961

ISBN: 0-7645-5589-

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

2B/SU/QT/QU/IN

About the Author

Janet Valade is the author of PHP 5 For Dummies as well as the first edition of this book. In addition, Janet has authored and revised chapters for Linux books, written chapters for a Certified Internet Webmaster (CIW) book, and written the Apache section for a book on LAMP (Linux, Apache, MySQL, and PHP).

Janet has 20 years of experience in the computing field. Most recently, she worked as a Web designer and programmer in a Unix/Linux environment for four years. Prior to that, Janet worked for 13 years in a university environ ment, where she was a systems analyst. During her tenure, she supervised the installation and operation of computing resources, designed and devel oped a data archive, supported faculty and students in their computer usage, wrote numerous technical papers, and developed and presented seminars on a variety of technology topics.

To keep in touch, see janet.valade.com.

Author’s Acknowledgments

First, I wish to express my appreciation to the entire open source community. Without those who give their time and talent, there would be no cool PHP and MySQL for me to write about. Furthermore, I never would have learned this software without the lists where people generously spend their time answering foolish questions from beginners.

I want to thank my mother for passing on a writing gene, along with many other things. And my children always for everything. My thanks to my friends Art, Dick, and Marge for responding to my last-minute call for help. I particu larly want to thank Sammy, Dude, Spike, Lucky, Upanishad, Sadie, and E.B. for their important contributions.

And, of course, I want to thank the professionals who make it all possible. Without my agent and the people at Wiley Publishing, Inc., this book would not exist. Because they all do their jobs so well, I can contribute my part to this joint project.

Publisher’s Acknowledgments

We’re proud of this book; please send us your comments through our online registration form located at www.dummies.com/register/.

Some of the people who helped bring this book to market include the following:

Acquisitions, Editorial, and Media Development

Senior Project Editor: Pat O’Brien Acquisitions Editor: Terri Varveris Senior Copy Editor: Teresa Artman Technical Editor: Craig Lukasik Editorial Manager: Kevin Kirschner Permissions Editor: Laura Moss Media Development Specialist: Kit Malone Media Development Manager: Laura VanWinkle Media Development Supervisor: Richard Graves Editorial Assistant: Amanda Foxworth Cartoons: Rich Tennant, www.the5thwave.com

Production Project Coordinator: Maridee Ennis Layout and Graphics: Andrea Dahl, Joyce Haughey, Stephanie D. Jumper, Kristin McMullan, Lynsey Osborn Proofreaders: Andy Hollandbeck, Carl William Pierce, Brian H. Walls, TECHBOOKS Publishing Services Indexer: TECHBOOKS Publishing Services

Publishing and Editorial for Technology Dummies

Richard Swadley, Vice President and Executive Group Publisher Andy Cummings, Vice President and Publisher Mary C. Corder, Editorial Director

Publishing for Consumer Dummies

Diane Graves Steele, Vice President and Publisher Joyce Pepple, Acquisitions Director

Composition Services

Gerry Fahey, Vice President of Production Services Debbie Stailey, Director of Composition Services

Table of Contents

  • Introduction
  • Using PHP and MySQL Part I: Developing a Web Database Application
  • Chapter 1: Introduction to PHP and MySQL
  • Chapter 2: Setting Up Your Work Environment
  • Chapter 3: Developing a Web Database Application
  • Part II: MySQL Database
  • Chapter 4: Building the Database
  • Chapter 5: Protecting Your Data
  • Part III: PHP
  • Chapter 6: General PHP
  • Chapter 7: PHP Building Blocks for Programs
  • Chapter 8: Data In, Data Out
  • Chapter 9: Moving Information from One Web Page to the Next
  • Part IV: Applications
  • Chapter 10: Putting It All Together
  • Chapter 11: Building an Online Catalog
  • Chapter 12: Building a Members Only Web Site
  • Part V: The Part of Tens
  • Chapter 13: Ten Things You Might Want to Do Using PHP Functions
  • Chapter 14: Ten PHP Gotchas
  • Part VI: Appendixes
  • Appendix A: Installing MySQL
  • Appendix B: Installing PHP
  • Appendix C: Installing and Configuring Apache
  • Index
  • Introduction
  • About This Book
  • Conventions Used in This Book
  • What You’re Not to Read
  • Foolish Assumptions
  • How This Book Is Organized
  • Using PHP and MySQL Part I: Developing a Web Database Application
  • Part II: MySQL Database
  • Part III: PHP
  • Part IV: Applications
  • Part V: The Part of Tens
  • Part VI: Appendixes
  • Icons Used in This Book
  • Where to Go from Here
  • Using PHP and MySQL Part I: Developing a Web Database Application
  • Chapter 1: Introduction to PHP and MySQL
  • What Is a Web Database Application?
  • The database
  • The application: Moving data in and out of the database
  • MySQL, My Database
  • Advantages of MySQL
  • How MySQL works
  • Communicating with the MySQL server
  • PHP, a Data Mover
  • Advantages of PHP
  • How PHP works
  • MySQL and PHP, the Perfect Pair
  • Advantages of the relationship
  • How MySQL and PHP work together
  • Keeping Up with PHP and MySQL Changes
  • Chapter 2: Setting Up Your Work Environment
  • The Required Tools
  • Finding a Place to Work
  • A company Web site
  • A Web hosting company
  • Setting up and running your own Web site
  • Testing, Testing, 1, 2, xii PHP & MySQL For Dummies, 2nd Edition
  • Testing PHP
  • Testing MySQL
  • Chapter 3: Developing a Web Database Application
  • Planning Your Web Database Application
  • Identifying what you want from the application
  • Taking the user into consideration
  • Making the site easy to use
  • Leaving room for expansion
  • Writing it down
  • Presenting the Two Running Examples in This Book
  • Stuff for Sale
  • Members Only
  • Designing the Database
  • Choosing the data
  • Organizing the data
  • Designing the Sample Databases
  • Pet Catalog design process
  • Members Only design process
  • Types of Data
  • Character data
  • Numerical data
  • Date and time data
  • Enumeration data
  • MySQL data type names
  • Writing it down
  • Taking a Look at the Sample Database Designs
  • Stuff for Sale database tables
  • Members Only database tables
  • Developing the Application
  • Building the database
  • Writing the programs
  • Part II: MySQL Database
  • Chapter 4: Building the Database
  • Communicating with MySQL
  • Building SQL queries
  • Sending SQL queries
  • Building a Database
  • Creating a new database
  • Deleting a database
  • Adding tables to a database
  • Changing the database structure
  • Moving Data In and Out of the Database Table of Contents xiii
  • Adding information
  • Retrieving information
  • Combining information from tables
  • Updating information
  • Removing information
  • Chapter 5: Protecting Your Data
  • Controlling Access to Your Data
  • Understanding account names and hostnames
  • Finding out about passwords
  • Taking a look at account permissions
  • Setting Up MySQL Accounts
  • Identifying what accounts currently exist
  • Adding new accounts and changing permissions
  • Adding and changing passwords
  • Removing permissions
  • Removing accounts
  • Backing Up Your Data
  • Restoring Your Data
  • Repairing tables
  • Restoring from a backup copy
  • Part III: PHP
  • Chapter 6: General PHP
  • Adding a PHP Section to an HTML Page
  • Writing PHP Statements
  • Using PHP Variables
  • Naming a variable
  • Creating and assigning values to variables
  • Dealing with notices
  • Using PHP Constants
  • Working with Numbers
  • Working with Character Strings
  • Single-quoted strings versus double-quoted strings
  • Joining strings.....................................................................................
  • Working with Dates and Times
  • Formatting a date
  • Storing a timestamp in a variable
  • Using dates with MySQL
  • Comparing Values
  • Making simple comparisons
  • Matching character strings to patterns
  • Joining Comparisons with and/or/xor
  • Adding Comments to Your Program
  • Chapter 7: PHP Building Blocks for Programs xiv PHP & MySQL For Dummies, 2nd Edition
  • Useful Simple Statements
  • Using echo statements
  • Using assignment statements
  • Using increment statements
  • Using exit
  • Using function calls
  • Using PHP Arrays
  • Creating arrays
  • Viewing arrays
  • Removing values from arrays
  • Sorting arrays
  • Getting values from arrays
  • Walking through an array
  • Multidimensional arrays
  • Useful Conditional Statements
  • Using if statements
  • Using switch statements
  • Using Loops
  • Using for loops
  • Using while loops
  • Using do..while loops
  • Infinite loops
  • Breaking out of a loop
  • Using Functions
  • Using variables in functions
  • Passing values between a function and the main program
  • Using built-in functions
  • Chapter 8: Data In, Data Out
  • PHP/MySQL Functions
  • Making a Connection
  • Connecting to the MySQL server
  • Selecting the right database
  • Sending SQL queries
  • Getting Information from a Database
  • Sending a SELECT query
  • Getting and using the data
  • Using functions to get data
  • Getting Information from the User
  • Using HTML forms
  • Making forms dynamic
  • Using the information from the form
  • Checking the information
  • Giving users a choice with multiple submit buttons
  • Putting Information into a Database
  • Preparing the data
  • Adding new information
  • Updating existing information
  • Getting Information in Files Table of Contents xv
  • Using a form to upload the file
  • Processing the uploaded file
  • Putting it all together
  • to the Next Chapter 9: Moving Information from One Web Page
  • Moving Your User from One Page to Another
  • Moving Information from Page to Page
  • Adding information to the URL
  • Storing information via cookies
  • Passing information with HTML forms
  • Using PHP Sessions
  • How PHP sessions work
  • Opening sessions
  • Using PHP session variables
  • Sessions without cookies
  • Making sessions private
  • Closing PHP sessions
  • Part IV: Applications
  • Chapter 10: Putting It All Together
  • Organizing the Application
  • Organizing at the application level
  • Organizing at the program level
  • Keeping It Private
  • Ensure the security of the computer
  • Don’t let the Web server display filenames
  • Hide things
  • Don’t trust information from users
  • Use a secure Web server
  • Completing Your Documentation
  • Chapter 11: Building an Online Catalog
  • Designing the Application
  • Showing pets to the customers
  • Adding pets to the catalog
  • Building the Database
  • Building the Pet table
  • Building the PetType table
  • Building the Color table
  • Adding data to the database
  • Designing the Look and Feel
  • Showing pets to the customers
  • Adding pets to the catalog
  • Writing the Programs xvi PHP & MySQL For Dummies, 2nd Edition
  • Showing pets to the customers
  • Adding pets to the catalog
  • Chapter 12: Building a Members Only Web Site
  • Designing the Application
  • Building the Database
  • Building the Member table
  • Building the Login table
  • Adding data to the database
  • Designing the Look and Feel
  • Storefront page
  • Login page
  • New Member Welcome page
  • Members Only section
  • Writing the Programs
  • Writing PetShopFront
  • Writing Login
  • Writing New_member
  • Writing the Members Only section
  • Planning for Growth
  • Part V: The Part of Tens
  • PHP Functions Chapter 13: Ten Things You Might Want to Do Using
  • Communicate with MySQL
  • Send E-Mail
  • Use PHP Sessions
  • Stop Your Program
  • Handle Arrays
  • Check for Variables
  • Format Values
  • Compare Strings to Patterns
  • Find Out about Strings
  • Change the Case of Strings
  • Chapter 14: Ten PHP Gotchas
  • Missing Semicolons
  • Not Enough Equal Signs
  • Misspelled Variable Names
  • Missing Dollar Signs
  • Troubling Quotes
  • Invisible Output
  • Numbered Arrays
  • Including PHP Statements Table of Contents xvii
  • Missing Mates
  • Confusing Parentheses and Brackets
  • Part VI: Appendixes
  • Appendix A: Installing MySQL
  • On Windows
  • Downloading and installing MySQL
  • Starting the MySQL server
  • Setting up the server to start when the computer starts
  • On Linux/Unix
  • Using RPM (Linux only)
  • From binary files
  • From source files
  • On Mac
  • Configuring MySQL
  • Appendix B: Installing PHP
  • Installing PHP on Unix/Linux/Mac with Apache
  • On Unix/Linux
  • On Mac OS X
  • Installation Options
  • Configuring Apache for PHP
  • On Windows
  • Configuring Your Web Server for PHP
  • Configuring Apache
  • Configuring IIS
  • Configuring PHP
  • Appendix C: Installing and Configuring Apache
  • Selecting a Version of Apache
  • Installing Apache
  • On Linux/Unix
  • On Windows
  • On Mac
  • Configuring Apache
  • Changing settings
  • Changing the location of your Web space
  • Changing the port number
  • Index