PHP & MySQL: Novice to Ninja, 7th Edition

Book description

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

  • Gain a thorough understanding of PHP syntax
  • Master database design principles and SQL
  • Write robust, maintainable, best practice code
  • Build a working content management system (CMS)
  • And much more!

Publisher resources

View/Submit Errata

Table of contents

  1. PHP & MySQL: Novice to Ninja, 7th Edition
  2. Notice of Rights
  3. Notice of Liability
  4. Trademark Notice
  5. About SitePoint
  6. About the Author
  7. 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. Code Samples
      2. Tips, Notes, and Warnings
    10. Where to Find Help
      1. The SitePoint Forums
      2. The Code Archive
    11. Your Feedback
    12. Let’s Go
  8. Chapter 1: 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
      4. Server Setup 4: Docker
    2. Getting Started
      1. Installation on Windows
      2. Installation on macOS
      3. Installation on Linux
    3. Getting Started with Docker
      1. Connecting to the Server and Creating Your First File
    4. We’re All Set Up
  9. Chapter 2: Introducing PHP
    1. Basic Syntax and Statements
    2. Variables, Operators, and Comments
      1. Variables
      2. Operators
    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
    7. Hiding the Seams
      1. PHP Templates
      2. Security Concerns
      3. Many Templates, One Controller
    8. Bring On the Database
  10. Chapter 3: Introducing MySQL
    1. An Introduction to Databases
    2. MySQL
    3. Using MySQL Workbench to Run SQL Queries
    4. Creating a Database
    5. Structured Query Language
    6. Creating a Table
    7. Adding Data
    8. A Word of Warning
    9. Viewing Stored Data
    10. Modifying Stored Data
    11. Deleting Stored Data
    12. Let PHP Do the Typing
  11. Chapter 4: 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. Magic Quotes
    10. Prepared Statements
    11. Deleting Data from the Database
    12. Mission Accomplished
  12. Chapter 5: 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
  13. Chapter 6: 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
  14. Chapter 7: Improving the Insert and Update Functions
    1. Improving the Update Function
      1. 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
  15. Chapter 8: Objects and Classes
    1. Time for Class
    2. Public vs Private
    3. Protected
    4. Objects
    5. Class Variables
    6. Constructors
    7. Type Hinting
    8. Private Variables
    9. Constructor Property Promotion
    10. Using the DatabaseTable Class
    11. Updating the Controller to Use the Class
    12. DRY
    13. Creating a Controller Class
    14. Single Entry Point
    15. Keeping it DRY
    16. Template Variables
    17. Be Careful with extract
    18. Summary
  16. Chapter 9: Creating an Extensible Framework
    1. Search Engine Optimization
    2. Thinking Ahead: User Registration
      1. 1. Include the Relevant Controller
      2. 2. Create an Instance of the Controller
      3. Dependencies
      4. 3. Call the Action on the Correct Controller
      5. Done
    3. URL Rewriting
    4. Tidying Up
      1. Make it OOP
    5. Reusing Code on Different Websites
      1. Generic or Project-specific?
      2. Making EntryPoint Generic
    6. Autoloading
      1. Case Sensitivity
      2. Implement an Autoloader
    7. Redecorating
      1. Namespaces
      2. Autoloading with PSR-4
      3. And the REST
      4. Non-web Applications
    8. Enforcing Dependency Structure with Interfaces
    9. Error Handling
    10. Your Own Framework
  17. Chapter 10: Allowing Users to Register Accounts
    1. Validating Email Addresses
    2. Preventing the Same Person from Registering Twice
    3. Securely Storing Passwords
    4. Registration Complete
    5. Chapter Summary
  18. Chapter 11: Cookies, Sessions, and Access Control
    1. Cookies
    2. PHP Sessions
      1. Counting Visits with Sessions
    3. Access Control
      1. Logging In
      2. Protected Pages
    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
  19. Chapter 12: 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. Storing Permissions in the Database
      5. A Crash Course in Binary
      6. Be Bit-wise
      7. Back to PHP
      8. Storing Bitwise Permissions in the Database
      9. Join Table and Bitwise Approaches: Pros and Cons
      10. Cleaning Up
      11. Editing Other People’s Jokes
    9. Phew!
  20. Chapter 13: Content Formatting and Pagination
    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?

Product information

  • Title: PHP & MySQL: Novice to Ninja, 7th Edition
  • Author(s): Tom Butler
  • Release date: February 2022
  • Publisher(s): SitePoint
  • ISBN: 9781925836462