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