Home > Store > Data > MySQL

larger cover

Add To My Wish List

Register your product to gain access to bonus material or receive a coupon.

PHP and MySQL Web Development, 3rd Edition

Book

  • This product currently is not for sale.
Not for Sale

eBook (Watermarked)

  • Your Price: $31.99
  • List Price: $39.99
  • About Watermarked eBooks
  • This PDF will be accessible from your Account page after purchase and requires the free Adobe® Reader® software to read it.

    The eBook requires no passwords or activation to read. We customize your eBook by discretely watermarking it with your name, making it uniquely yours.

    Watermarked eBook FAQ

  • Description
  • Sample Content
  • Updates
  • Copyright 2005
  • Dimensions: Special (all other)
  • Pages: 984
  • Edition: 3rd
  • Book
  • ISBN-10: 0-672-32672-8
  • ISBN-13: 978-0-672-32672-1
  • eBook (Watermarked)
  • ISBN-10: 0-7686-6363-6
  • ISBN-13: 978-0-7686-6363-1

A new edition of this title is available, ISBN-10: 0672329166 ISBN-13: 9780672329166

 

We've taken the best and made it even better. The third edition of the best-selling PHP and MySQL Web Development has been updated to include material and code on MySQL 5, PHP 5 and on PHPs object model and validation. Through a clear, practical approach, you will learn to develop secure, dynamic websites by integrating and implementing the PHP scripting language and the MySQL database system. Real-world examples and working sample projects will give you a strong foundation on which to start building your own websites, complete with features such as SSL, shopping carts and payment systems. The accompanying CD includes the source code from each example in the book, the entire book in PDF format, and source code and binaries for PHP 5, MySQL 5 and Apache. Readers have called PHP and MySQL Web Development call it the best technical book they've ever read, but don't take their word for it. Find out for yourself!

 

 

Online Sample Chapters

Using Arrays

Using Arrays in PHP

Table of Contents

Introduction.

I. Using PHP

1. PHP Crash Course.

    Using PHP.

    Creating a Sample Application: Bob’s Auto Parts.

      Creating the Order Form.

      Processing the Form.

    Embedding PHP in HTML.

      Use of PHP Tags.

      PHP Tag Styles.

      PHP Statements.

      Whitespace.

      Comments.

    Adding Dynamic Content.

      Calling Functions.

      Using the date() Function.

    Accessing Form Variables.

      Form Variables.

      String Concatenation.

      Variables and Literals.

    Understanding Identifiers.

    Creating User-Declared Variables.

    Assigning Values to Variables.

    Examining Variable Types.

      PHP’s Data Types.

      Type Strength.

      Type Casting.

      Variable Variables.

    Declaring and Using Constants.

    Understanding Variable Scope.

    Using Operators.

      Arithmetic Operators.

      String Operators.

      Assignment Operators.

      Comparison Operators.

      Logical Operators.

      Bitwise Operators.

      Other Operators.

    Using Operators: Working Out the Form Totals.

    Understanding Precedence and Associativity: Evaluating Expressions.

    Using Variable Functions.

      Testing and Setting Variable Types.

      Testing Variable Status.

      Reinterpreting Variables.

    Implementing Control Structures.

    Making Decisions with Conditionals.

      if Statements.

      Code Blocks.

      else Statements.

      elseif Statements.

      switch Statements.

      Comparing the Different Conditionals.

    Repeating Actions Through Iteration.

      while Loops.

      for and foreach Loops.

      do..while Loops.

    Breaking Out of a Control Structure or Script.

    Employing Alternative Control Structure Syntax.

    Using declare.

    Next: Saving the Customer’s Order.

2. Storing and Retrieving Data.

    Saving Data for Later.

    Storing and Retrieving Bob’s Orders.

    Processing Files.

    Opening a File.

      Choosing File Modes.

      Using fopen() to Open a File.

      Opening Files Through FTP or HTTP.

      Addressing Problems Opening Files.

    Writing to a File.

      Parameters for fwrite().

      File Formats.

    Closing a File.

    Reading from a File.

      Opening a File for Reading: fopen().

      Knowing When to Stop: feof().

      Reading a Line at a Time: fgets(), fgetss(), and fgetcsv().

      Reading the Whole File: readfile(), fpassthru(), and file().

      Reading a Character: fgetc().

      Reading an Arbitrary Length: fread().

    Using Other Useful File Functions.

      Checking Whether a File Is There: file_exists().

      Determining How Big a File Is: filesize().

      Deleting a File: unlink().

      Navigating Inside a File: rewind(), fseek(), and ftell().

    Locking Files.

    Doing It a Better Way: Database Management Systems.

      Problems with Using Flat Files.

      How RDBMSs Solve These Problems.

    Further Reading.

    Next.

3. Using Arrays.

    What Is an Array?

    Numerically Indexed Arrays.

      Initializing Numerically Indexed Arrays.

      Accessing Array Contents.

      Using Loops to Access the Array.

    Arrays with Different Indices.

      Initializing an Array.

      Accessing the Array Elements.

      Using Loops.

    Array Operators.

    Multidimensional Arrays.

    Sorting Arrays.

      Using sort().

      Using asort() and ksort() to Sort Arrays.

      Sorting in Reverse.

    Sorting Multidimensional Arrays.

      User-Defined Sorts.

      Reverse User Sorts.

    Reordering Arrays.

      Using shuffle().

      Using array_reverse().

    Loading Arrays from Files.

    Performing Other Array Manipulations.

      Navigating Within an Array: each(), current(), reset(), end(), next(), pos(), and prev().

      Applying Any Function to Each Element in an Array: array_walk().

      Counting Elements in an Array: count(), sizeof(), and array_count_values().

      Converting Arrays to Scalar Variables: extract().

    Further Reading.

    Next.

4. String Manipulation and Regular Expressions.

    Creating a Sample Application: Smart Form Mail.

    Formatting Strings.

      Trimming Strings: chop(), ltrim(), and trim().

      Formatting Strings for Presentation.

      Formatting Strings for Storage: addslashes() and stripslashes().

    Joining and Splitting Strings with String Functions.

      Using explode(), implode(), and join().

      Using strtok().

      Using substr().

    Comparing Strings.

      Performing String Ordering: strcmp(), strcasecmp(), and strnatcmp().

      Testing String Length with strlen().

    Matching and Replacing Substrings with String Functions.

      Finding Strings in Strings: strstr(), strchr(), strrchr(), and stristr().

      Finding the Position of a Substring: strpos() and strrpos().

      Replacing Substrings: str_replace() and substr_replace().

    Introducing Regular Expressions.

      The Basics.

      Character Sets and Classes.

      Repetition.

      Subexpressions.

      Counted Subexpressions.

      Anchoring to the Beginning or End of a String.

      Branching.

      Matching Literal Special Characters.

      Reviewing the Special Characters.

      Putting It All Together for the Smart Form.

    Finding Substrings with Regular Expressions.

    Replacing Substrings with Regular Expressions.

    Splitting Strings with Regular Expressions.

    Comparing String Functions and Regular Expression Functions.

    Further Reading.

    Next.

5. Reusing Code and Writing Functions.

    Reusing Code.

      Cost.

      Reliability.

      Consistency.

    Using require() and include().

      require().

      Filename Extensions and require().

      PHP Tags and require().

    Using require() for Website Templates.

      Using include().

      Using require_once() and include_once().

      Using auto_prepend_file and auto_append_file.

    Using Functions in PHP.

      Calling Functions.

      Calling an Undefined Function.

      Understanding Case and Function Names.

    Understanding Why You Should Define Your Own Functions.

    Examining Basic Function Structure.

      Naming Your Function.

    Using Parameters.

    Understanding Scope.

    Passing by Reference Versus Passing by Value.

    Returning from Functions.

    Returning Values from Functions.

      Code Blocks.

    Implementing Recursion.

    Further Reading.

    Next.

6. Object-Oriented PHP.

    Understanding Object-Oriented Concepts.

      Classes and Objects.

      Polymorphism.

      Inheritance.

    Creating Classes, Attributes, and Operations in PHP.

      Structure of a Class.

      Constructors.

      Destructors.

    Instantiating Classes.

    Using Class Attributes.

    Controlling Access with private and public.

    Calling Class Operations.

    Implementing Inheritance in PHP.

      Controlling Visibility Through Inheritance with private and protected.

      Overriding.

      Preventing Inheritance and Overriding with final.

      Understanding Multiple Inheritance.

      Implementing Interfaces.

    Designing Classes.

    Writing the Code for Your Class.

    Understanding Advanced and New Object-Oriented Functionality in PHP.

      Note: PHP4 Versus PHP5.

      Using Per-Class Constants.

      Implementing Static Methods.

      Checking Class Type and Type Hinting.

      Cloning Objects.

      Using Abstract Classes.

      Overloading Methods with __call().

      Using __autoload().

      Implementing Iterators and Iteration.

      Converting Your Classes to Strings.

      Using the Reflection API.

    Next.

7. Exception Handling.

    Exception Handling Concepts.

    The Exception Class.

    User-Defined Exceptions.

    Exceptions in Bob’s Auto Parts.

    Exceptions and PHP’s Other Error Handling Mechanisms.

    Further Reading.

    Next.

II. Using MySQL

8. Designing Your Web Database.

    Relational Database Concepts.

      Tables.

      Columns.

      Rows.

      Values.

      Keys.

      Schemas.

      Relationships.

    How to Design Your Web Database.

      Think About the Real-World Objects You Are Modeling.

      Avoid Storing Redundant Data.

      Use Atomic Column Values.

      Choose Sensible Keys.

      Think About the Questions You Want to Ask the Database.

      Avoid Designs with Many Empty Attributes.

      Summary of Table Types.

    Web Database Architecture.

      Architecture.

    Further Reading.

    Next.

9. Creating Your Web Database.

    Using the MySQL Monitor.

    Logging In to MySQL.

    Creating Databases and Users.

      Creating the Database.

    Setting Up Users and Privileges.

    Introducing MySQL’s Privilege System.

      Principle of Least Privilege.

      User Setup: The GRANT Command.

      Types and Levels of Privileges.

      The REVOKE Command.

      Examples Using GRANT and REVOKE.

    Setting Up a User for the Web.

      Logging Out as root.

    Using the Right Database.

    Creating Database Tables.

      Understanding What the Other Keywords Mean.

      Understanding the Column Types.

      Looking at the Database with SHOW and DESCRIBE.

      Creating Indexes.

      A Note on Table Types.

    Understanding MySQL Identifiers.

    Choosing Column Data Types.

      Numeric Types.

    Further Reading.

    Next.

10. Working with Your MySQL Database.

    What Is SQL?

     Inserting Data into the Database.

    Retrieving Data from the Database.

      Retrieving Data with Specific Criteria.

      Retrieving Data from Multiple Tables.

      Retrieving Data in a Particular Order.

      Grouping and Aggregating Data.

      Choosing Which Rows to Return.

      Using Subqueries.

    Updating Records in the Database.

    Altering Tables After Creation.

    Deleting Records from the Database.

    Dropping Tables.

    Dropping a Whole Database.

    Further Reading.

    Next.

11. Accessing Your MySQL Database from the Web with PHP.

    How Web Database Architectures Work.

    Querying a Database from the Web.

    Checking and Filtering Input Data.

    Setting Up a Connection.

    Choosing a Database to Use.

    Querying the Database.

    Retrieving the Query Results.

    Disconnecting from the Database.

    Putting New Information in the Database.

    Using Prepared Statements.

    Using Other PHP-Database Interfaces.

    Using a Generic Database Interface: PEAR DB.

    Further Reading.

    Next.

12. Advanced MySQL Administration.

    Understanding the Privilege System in Detail.

      The user Table.

      The db and host Tables.

      The tables_priv and columns_priv Tables.

      Access Control: How MySQL Uses the Grant Tables.

      Updating Privileges: When Do Changes Take Effect?

    Making Your MySQL Database Secure.

      MySQL from the Operating System’s Point of View.

      Passwords.

      User Privileges.

      Web Issues.

    Getting More Information About Databases.

      Getting Information with SHOW.

      Getting Information About Columns with DESCRIBE.

      Understanding How Queries Work with EXPLAIN.

    Speeding Up Queries with Indexes.

    Optimizing Your Database.

      Design Optimization.

      Permissions.

      Table Optimization.

      Using Indexes.

      Using Default Values.

      Other Tips.

    Backing Up Your MySQL Database.

    Restoring Your MySQL Database.

    Implementing Replication.

      Setting Up the Master.

      Performing the Initial Data Transfer.

      Setting Up the Slave or Slaves.

    Further Reading.

    Next.

13. Advanced MySQL Programming.

    The LOAD DATA INFILE Statement.

    Storage Engines.

    Transactions.

      Understanding Transaction Definitions.

      Using Transactions with InnoDB.

    Foreign Keys.

    Stored Procedures.

      Basic Example.

      Local Variables.

      Cursors and Control Structures.

    Further Reading.

    Next.

III. E-COMMERCE AND SECURITY.

14. Running an E-commerce Site.

    Deciding What You Want to Achieve.

    Considering the Types of Commercial Websites.

      Publishing Information Using Online Brochures.

      Taking Orders for Goods or Services.

      Providing Services and Digital Goods.

      Adding Value to Goods or Services.

      Cutting Costs.

    Understanding Risks and Threats.

      Crackers.

      Failure to Attract Sufficient Business.

      Computer Hardware Failure.

      Power, Communication, Network, or Shipping Failures.

      Extensive Competition.

      Software Errors.

      Evolving Governmental Policies and Taxes.

      System Capacity Limits.

    Deciding on a Strategy.

    Next.

15. E-commerce Security Issues.

    How Important Is Your Information?

    Security Threats.

      Exposure of Confidential Data.

      Loss or Destruction of Data.

      Modification of Data.

      Denial of Service.

      Errors in Software.

      Repudiation.

    Usability, Performance, Cost, and Security.

    Security Policy Creation.

    Authentication Principles.

    Authentication.

    Encryption Basics.

    Private Key Encryption.

    Public Key Encryption.

    Digital Signatures.

    Digital Certificates.

    Secure Web Servers.

    Auditing and Logging.

    Firewalls.

    Data Backups.

      Backing Up General Files.

      Backing Up and Restoring Your MySQL Database.

    Physical Security.

    Next.

16. Implementing Authentication with PHP and MySQL.

    Identifying Visitors.

    Implementing Access Control.

      Storing Passwords.

      Encrypting Passwords.

      Protecting Multiple Pages.

    Using Basic Authentication.

    Using Basic Authentication in PHP.

    Using Basic Authentication with Apache’s .htaccess Files.

    Using Basic Authentication with IIS.

    Using mod_auth_mysql Authentication.

      Installing mod_auth_mysql.

      Did It Work?

      Using mod_auth_mysql.

    Creating Your Own Custom Authentication.

    Further Reading.

    Next.

17. Implementing Secure Transactions with PHP and MySQL.

    Providing Secure Transactions.

      The User’s Machine.

      The Internet.

      Your System.

    Using Secure Sockets Layer (SSL).

    Screening User Input.

    Providing Secure Storage.

    Determining Whether to Store Credit Card Numbers.

    Using Encryption in PHP.

    Further Reading.

    Next.

IV. ADVANCED PHP TECHNIQUES.

18. Interacting with the File System and the Server.

    Uploading Files.

      HTML for File Upload.

      A Note on Security.

      Writing the PHP to Deal with the File.

      Common Problems.

    Using Directory Functions.

      Reading from Directories.

      Getting Information About the Current Directory.

      Creating and Deleting Directories.

     Interacting with the File System.

      Getting File Information.

      Changing File Properties.

      Creating, Deleting, and Moving Files.

    Using Program Execution Functions.

    Interacting with the Environment: getenv() and putenv().

    Further Reading.

    Next.

19. Using Network and Protocol Functions.

    Examining Available Protocols.

    Sending and Reading Email.

    Using Other Websites.

    Using Network Lookup Functions.

    Using FTP.

      Using FTP to Back Up or Mirror a File.

      Uploading Files.

      Avoiding Timeouts.

      Using Other FTP Functions.

    Further Reading.

    Next.

20. Managing the Date and Time.

    Getting the Date and Time from PHP.

      Using the date() Function.

      Dealing with Unix Timestamps.

      Using the getdate() Function.

      Validating Dates.

    Converting Between PHP and MySQL Date Formats.

    Calculating Dates in PHP.

    Calculating Dates in MySQL.

    Using Microseconds.

    Using the Calendar Functions.

    Further Reading.

    Next.

21. Generating Images.

    Setting Up Image Support in PHP.

    Understanding Image Formats.

      JPEG.

      PNG.

      WBMP.

      GIF.

    Creating Images.

      Creating a Canvas Image.

      Drawing or Printing Text on the Image.

      Outputting the Final Graphic.

      Cleaning Up.

    Using Automatically Generated Images in Other Pages.

    Using Text and Fonts to Create Images.

      Setting Up the Base Canvas.

      Fitting the Text onto the Button.

      Positioning the Text.

      Writing the Text onto the Button.

      Finishing Up.

    Drawing Figures and Graphing Data.

    Using Other Image Functions.

    Further Reading.

    Next.

22. Using Session Control in PHP.

    What Session Control Is.

    Understanding Basic Session Functionality.

      What Is a Cookie?

      Setting Cookies from PHP.

      Using Cookies with Sessions.

      Storing the Session ID.

    Implementing Simple Sessions.

      Starting a Session.

      Registering Session Variables.

      Using Session Variables.

      Unsetting Variables and Destroying the Session.

    Creating a Simple Session Example.

    Configuring Session Control.

    Implementing Authentication with Session Control.

    Further Reading.

    Next.

23. Other Useful Features.

    Using Magic Quotes.

    Evaluating Strings: eval().

    Terminating Execution: die and exit.

    Serializing Variables and Objects.

    Getting Information About the PHP Environment.

      Finding Out What Extensions Are Loaded.

      Identifying the Script Owner.

      Finding Out When the Script Was Modified.

    Loading Extensions Dynamically.

    Temporarily Altering the Runtime Environment.

    Highlighting Source Code.

    Using PHP on the Command Line.

    Next.

V. BUILDING PRACTICAL PHP AND MySQL PROJECTS24. USING PHP AND MySQL FOR LARGE PROJECTS.

    Applying Software Engineering to Web Develop-ment.

    Planning and Running a Web Application Project.

    Reusing Code.

    Writing Maintainable Code.

      Coding Standards.

      Breaking Up Code.

      Using a Standard Directory Structure.

      Documenting and Sharing In-House Functions.

    Implementing Version Control.

    Choosing a Development Environment.

    Documenting Your Projects.

    Prototyping.

    Separating Logic and Content.

    Optimizing Code.

      Using Simple Optimizations.

      Using Zend Products.

    Testing.

    Further Reading.

    Next.

25. Debugging.

    Programming Errors.

      Syntax Errors.

      Runtime Errors.

      Logic Errors.

    Variable Debugging Aid.

    Error Reporting Levels.

    Altering the Error Reporting Settings.

    Triggering Your Own Errors.

    Handling Errors Gracefully.

    Next.

26. Building User Authentication and Personalization.

    The Problem.

    Solution Components.

      User Identification and Personalization.

      Storing Bookmarks.

      Recommending Bookmarks.

    Solution Overview.

    Implementing the Database.

    Implementing the Basic Site.

    Implementing User Authentication.

      Registering.

      Logging In.

      Logging Out.

      Changing Passwords.

      Resetting Forgotten Passwords.

    Implementing Bookmark Storage and Retrieval.

      Adding Bookmarks.

      Displaying Bookmarks.

      Deleting Bookmarks.

    Implementing Recommendations.

    Wrapping Up and Considering Possible Extensions.

    Next.

27. Building a Shopping Cart.

    The Problem.

    Solution Components.

      Building an Online Catalog.

      Tracking Users’ Purchases While They Shop.

      Implementing a Payment System.

      Building an Administration Interface.

    Solution Overview.

    Implementing the Database.

    Implementing the Online Catalog.

      Listing Categories.

      Listing Books in a Category.

      Showing Book Details.

    Implementing the Shopping Cart.

      Using the show_cart.php Script.

      Viewing the Cart.

      Adding Items to the Cart.

      Saving the Updated Cart.

      Printing a Header Bar Summary.

      Checking Out.

    Implementing Payment.

    Implementing an Administration Interface.

    Extending the Project.

    Using an Existing System.

    Next.

28. Building a Content Management System.

    The Problem.

    Solution Requirements.

    Existing Systems.

    Editing Content.

      Getting Content into the System.

      Databases Versus File Storage.

      Document Structure.

    Using Metadata.

    Formatting the Output.

    Solution Design/Overview.

    Designing the Database.

    Implementing the CMS.

      Front End.

      Back End.

      Searches.

      Editor Screen.

    Extending the Project.

    Next.

29. Building a Web-Based Email Service.

    The Problem.

    Solution Components.

    Solution Overview.

    Setting Up the Database.

    Examining the Script Architecture.

    Logging In and Out.

    Setting Up Accounts.

      Creating a New Account.

      Modifying an Existing Account.

      Deleting an Account.

    Reading Mail.

      Selecting an Account.

      Viewing Mailbox Contents.

      Reading a Mail Message.

      Viewing Message Headers.

      Deleting Mail.

    Sending Mail.

      Sending a New Message.

      Replying To or Forwarding Mail.

    Extending the Project.

    Next.

30. Building a Mailing List Manager.

    The Problem.

    Solution Components.

      Setting Up a Database of Lists and Subscribers.

      Using File Upload.

      Sending Mail with Attachments.

    Solution Overview.

    Setting Up the Database.

    Defining the Script Architecture.

    Implementing Login.

      Creating a New Account.

      Logging In.

    Implementing User Functions.

      Viewing Lists.

      Viewing List Information.

      Viewing List Archives.

      Subscribing and Unsubscribing.

      Changing Account Settings.

      Changing Passwords.

      Logging Out.

    Implementing Administrative Functions.

      Creating a New List.

      Uploading a New Newsletter.

      Handling Multiple File Upload.

      Previewing the Newsletter.

      Sending the Message.

    Extending the Project.

    Next.

31. Building Web Forums.

    The Problem.

    Solution Components.

    Solution Overview.

    Designing the Database.

    Viewing the Tree of Articles.

      Expanding and Collapsing.

      Displaying the Articles.

      Using the treenode Class.

    Viewing Individual Articles.

    Adding New Articles.

    Adding Extensions.

    Using an Existing System.

    Next.

32. Generating Personalized Documents in Portable Document Format (PDF).

    The Problem.

      Evaluating Document Formats.

    Solution Components.

      Question and Answer System.

      Document Generation Software.

    Solution Overview.

      Asking the Questions.

      Grading the Answers.

      Generating an RTF Certificate.

      Generating a PDF Certificate from a Template.

      Generating a PDF Document Using PDFlib.

      A Hello World Script for PDFlib.

      Generating a Certificate with PDFlib.

    Handling Problems with Headers.

    Extending the Project.

    Further Reading.

    Next.

33. Connecting to Web Services with XML and SOAP.

    The Problem.

      Understanding XML.

      Understanding Web Services.

    Solution Components.

      Building a Shopping Cart.

      Using Amazon’s Web Services Interfaces.

      Parsing XML.

      Using SOAP with PHP.

      Caching.

    Solution Overview.

      Core Application.

      Showing Books in a Category.

      Getting an AmazonResultSet Class.

      Using REST/XML Over HTTP.

      Using SOAP.

      Caching the Data.

      Building the Shopping Cart.

      Checking Out to Amazon.

    Installing the Project Code.

    Extending the Project.

    Further Reading.

VI. APPENDIXES.

Appendix A: Installing PHP and MySQL.

    Running PHP as a CGI Interpreter or Module.

    Installing Apache, PHP, and MySQL Under Unix.

      Binary Installation.

      Source Installation.

      httpd.conf File: Snippets.

      Is PHP Support Working?

      Is SSL Working?

    Installing Apache, PHP, and MySQL Under Windows.

      Installing MySQL Under Windows.

      Installing Apache Under Windows.

      Installing PHP for Windows.

    Installing PEAR.

    Setting Up Other Configurations.

Appendix B: Web Resources.

    PHP Resources.

    MySQL and SQL Specific Resources.

    Apache Resources.

    Web Development.

Index.

 

FREE

ONE MONTH ACCESS!

WITH PURCHASE


Get unlimited 30-day access to thousands of Books & Training Videos about technology, professional development and digital media If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months.