O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

PHP & MySQL: Novice to Ninja, 6th Edition

Book Description

PHP & MySQL: Novice to Ninja, 6th Edition is a hands-on guide to learning all the tools, principles, and techniques needed to build a fully functional application using PHP & MySQL. Comprehensively updated to cover PHP 7 and modern best practice, this practical and fun book covers everything from installing PHP and MySQL through to creating a complete online content management system.

You'll learn how to:

  • Install PHP & MySQL on Windows, Mac OS X, or Linux
  • Gain a thorough understanding of PHP syntax
  • Use object oriented programming techniques
  • Master database design principles and SQL
  • Develop robust websites that can handle high levels of traffic
  • Build a working content management system (CMS)
  • And much more!

Table of Contents

  1. PHP & MySQL: Novice to Ninja, 6th Edition
  2. Notice of Rights
  3. Notice of Liability
  4. Trademark Notice
  5. About Tom Butler
  6. About Kevin Yank
  7. About SitePoint
  8. Preface
    1. Who Should Read This Book
    2. Programming Has Changed
    3. It Takes 10,000 Hours to Become an Expert
    4. Resist the Temptation to Skip Ahead
    5. The Concorde Fallacy
    6. You’re Not Learning PHP
    7. Getting Braces and Semicolons in the Right Place Is the Easy Part
    8. You Won’t Get Anything Done by Planning
      1. Okay, Design Isn’t All Bad
    9. Conventions Used
      1. Tips, Notes, and Warnings
    10. Supplementary Materials
  9. Installation
    1. Your Own Web Server
      1. Server Setup 1: Manually Installing All the Software Components
      2. Server Setup 2: Pre-packaged Installations
      3. Server Setup 3: Virtual Servers
    2. Your Own Virtual Server
      1. Installation on Windows
      2. Installation on macOS
      3. Installation on Linux
    3. Getting Started with Vagrant
  10. Introducing PHP
    1. Basic Syntax and Statements
    2. Variables, Operators, and Comments
      1. Variables
      2. Operators
      3. Comments
    3. Control Structures
      1. If Statements
      2. Loops
    4. Arrays
    5. User Interaction and Forms
      1. Passing Variables in Links
    6. Passing Variables in Forms
      1. GET or POST?
    7. Hiding the Seams
      1. PHP Templates
      2. Security Concerns
      3. Many Templates, One Controller
    8. Bring on the Database
  11. Introducing MySQL
    1. An Introduction to Databases
    2. Using MySQL Workbench to Run SQL Queries
    3. Creating a Database
    4. Structured Query Language
    5. Creating a Table
    6. Adding Data
    7. A Word of Warning
    8. Viewing Stored Data
    9. Modifying Stored Data
    10. Deleting Stored Data
    11. Let PHP Do the Typing
  12. Publishing MySQL Data on the Web
    1. The Big Picture
    2. Creating a MySQL User Account
    3. Connecting to MySQL with PHP
    4. A Crash Course in Object-oriented Programming
      1. Configuring the Connection
    5. Sending SQL Queries with PHP
    6. Handling SELECT Result Sets
    7. Thinking Ahead
    8. Inserting Data into the Database
    9. Deleting Data from the Database
    10. Mission Accomplished
  13. Relational Database Design
    1. Giving Credit Where Credit Is Due
    2. Rule of Thumb: Keep Entities Separate
    3. SELECT with Multiple Tables
    4. Simple Relationships
    5. Many-to-many Relationships
    6. One for Many, and Many for One
  14. Structured PHP Programming
    1. Include Files
      1. Including HTML Content
      2. Including PHP Code
      3. Types of Includes
    2. Custom Functions and Function Libraries
      1. Variable Scope
    3. Breaking Up Your Code Into Reusable Functions
      1. Using Functions to Replace Queries
      2. Updating Jokes
      3. Editing Jokes on the Website
      4. Delete Function
      5. Select Function
    4. The Best Way
  15. Improving the Insert and Update Functions
    1. Improving the Update Function
      1. Stripping the Trailing Comma
      2. Improving the Insert Function
    2. Handling Dates
      1. Displaying the Joke Date
    3. Making Your Own Tools
    4. Generic Functions
    5. Using These Functions
    6. Repeated Code Is the Enemy
      1. Creating a Page for Adding and Editing
    7. Further Polishing
    8. Moving Forward
  16. Objects and Classes
    1. Time for Class
    2. Public vs Private
    3. Objects
    4. Class Variables
    5. Constructors
    6. Type Hinting
    7. Private Variables
    8. Using the DatabaseTable Class
    9. Updating the Controller to Use the Class
    10. DRY
    11. Creating a Controller Class
    12. Single Entry Point
    13. Keeping it DRY
    14. Template Variables
    15. Be Careful With Extract
  17. Creating an Extensible Framework
    1. Search Engines
    2. Make Things Generic
    3. Thinking Ahead: User Registration
    4. Dependencies
    5. URL Rewriting
    6. Tidying Up
      1. Make it OOP
    7. Reusing Code on Different Websites
    8. Generic or Project Specific?
      1. Making EntryPoint Generic
    9. Autoloading and Namespaces
    10. Case Sensitivity
    11. Implement an Autoloader
    12. Redecorating
    13. Namespaces
    14. Autoloading with PSR-4
    15. A Note on Composer
    16. And the REST
    17. Enforcing Dependency Structure with Interfaces
    18. Your Own Framework
  18. Allowing Users to Register Accounts
    1. Validating Email Addresses
    2. Preventing the Same Person from Registering Twice
    3. Securely Storing Passwords
    4. Registration Complete
  19. Cookies, Sessions, and Access Control
    1. Cookies
    2. PHP Sessions
      1. Counting Visits with Sessions
    3. Access Control
      1. Logging In
      2. Protected Pages
      3. Interfaces and Return Types
      4. Making Use of the Authentication Class
      5. Login Error Message
    4. Creating a Login Form
    5. Logging Out
      1. Assigning Added Jokes to the Logged-in User
      2. User Permissions
      3. Mission Accomplished?
    6. The Sky’s the Limit
  20. MySQL Administration
    1. Backing Up MySQL Databases
      1. Database Backups Using MySQL Workbench
      2. Database Backups Using mysqlpump
      3. Incremental Backups Using Binary Logs
    2. MySQL Access Control Tips
      1. Host Name Issues
      2. Locked Out?
    3. Indexes
      1. Multicolumn Indexes
    4. Foreign Keys
    5. Better Safe than Sorry
  21. Relationships
    1. Object Relational Mappers
      1. Public Properties
      2. Methods in Entity Classes
      3. Using Entity Classes from the DatabaseTable Class
      4. Joke Objects
      5. Using the Joke Class
      6. References
      7. Simplifying the List Controller Action
    2. Tidying Up
      1. Caching
    3. Joke Categories
      1. List Page
    4. Assigning Jokes to Categories
      1. Assigning Categories to Jokes
    5. Displaying Jokes by Category
    6. Editing Jokes
    7. User Roles
    8. Creating a Form to Assign Permissions
      1. Author List
      2. Edit Author Permissions
      3. Setting Permissions
      4. A Different Approach
      5. A Crash Course in Binary
      6. Be Bit-Wise
      7. Back to PHP
      8. Storing Bitwise Permissions in the Database
      9. Join Table or Bitwise
      10. Cleaning Up
      11. Editing Others’ Jokes
    9. Phew!
  22. Content Formatting with Regular Expressions
    1. Regular Expressions
    2. String Replacement with Regular Expressions
      1. Emphasized Text
      2. Paragraphs
      3. Hyperlinks
    3. Putting It All Together
    4. Sorting, Limiting and Offsets
      1. Sorting
      2. Pagination with LIMIT and OFFSET
      3. Pagination in Categories
    5. Achievement Unlocked: Ninja
      1. What Next?
  23. Using The Sample Code Repository
    1. Some Caveats
      1. When You Switch to a Sample, Any Files in the Project Directory Will Be Removed
      2. Sample Database
  24. Linux Troubleshooting