My Cart (0)

Customer Service 1-800-221-5528

Murach’s PHP and MySQL (4th Edition)

by Joel Murach and Ray Harris
23 chapters, 848 pages, 360 illustrations
Published August 2022
ISBN 978-1-943873-00-5
Print: $59.50
eBook: $54.50
Print + eBook: $72.00

Quickly and easily learn how to build database-driven websites with Murach’s PHP and MySQL! PHP and MySQL are two of today’s most popular open-source tools for server-side web programming. And with this book, you’ll learn right from the start how to use them together, the same way the pros do. You’ll create a functional, interactive database and website for a store in the first six chapters. Then, the rest of the book builds out your PHP and MySQL skills to the professional level, teaching you today's best practices.

College Instructors

Go to our instructor's site to learn more about this book and its instructor's materials.

 

Along with the great organization, ease of learning, and thorough coverage of the technologies and programming practices, this book is simply a pleasure to read. Any developer/techie/geek should enjoy it. A solid 5-star rating all the way."

Jeff Salter, Developer, Sacramento, California

  • About this Book
  • Table of Contents
  • FREE Downloads
  • Book FAQs
  • Corrections
  • Reviews

Who this book is for

This book is for anyone who wants to learn how to build and maintain websites that use PHP and MySQL (or MySQL’s alternative, MariaDB). It is explicitly written to be accessible for anyone, even people with no prior programming experience, while additionally serving as a thorough reference for experience coders.

The only prerequisite for this book is that you have some elementary HTML and CSS skills. If you don’t have these skills or if you want to add to your skill set, we recommend Murach’s HTML and CSS (5th Edition).

What this book does

This book gets you started with PHP and MySQL as quickly as possible and then builds out your skills in a professional way. To make it easy to set your own pace, this book is divided into four sections.

Section 1: Get started fast with PHP and MySQL

This section gets you off to a fast start whether or not you have any prior programming experience. Chapter 2 presents a complete subset of PHP; chapter 3 shows you how to use a MySQL database; chapter 4 shows you how to develop database applications with PHP; chapter 5 shows how to structure the code in your applications by using the MVC pattern; and chapter 6 shows you how to test and debug your web applications.

This section uses a self-paced approach that lets experienced programmers move more quickly while beginners work at a pace that’s comfortable for absorbing all of the new information. When you finish this section, you’ll understand how all the pieces of a web application fit together, and you’ll be ready for rapid progress in the sections that follow. Most importantly, you’ll be able to build complete database-driven web applications of your own!

Section 2: Master PHP programming

In this section, you’ll expand your PHP skills to include the professional skills you’ll need on the job every day. That means you’ll soon be coding applications that use key concepts like arrays, functions, regular expressions, exception handling, libraries, and your own objects. The last application in this section illustrates an object-oriented approach to data validation that you can use as a model for data validation in your own applications.

Section 3: Master MySQL programming

Section 3 expands your MySQL and PHP skills to build full-fledged database-driven web applications from the ground up. You'll learn:

  • How to design a database
  • How to use SQL DDL statements to create a database
  • How to use SQL DML statements to extract and update the data in a database
  • The advanced PHP skills that you need for developing database applications

Section 4: Advanced skills for building websites

The last section in this book rounds out your web development skills by showing how to:

  • Use secure connections and hash passwords
  • Authenticate users
  • Advanced methods for working with uploads, files, and images

These skills ensure that your web applications are trustworthy, reliable, and fully professional. Then, the last chapter in this section shows how to put everything together in an e-commerce web site.

Why you’ll learn faster and better with this book

Like all our books, Murach’s PHP and MySQL has features that you won’t find elsewhere. That’s why we believe you’ll learn faster and better with our book than with any other. Here are just a few of those features:

  • You’re ready for productive work right away - Section 1 presents a complete subset of PHP and MySQL in just 6 chapters and 206 pages.
  • Go from beginner to professional in a single book - The final three sections present all of the skills that you need for developing web applications at a professional level.
  • Effective exercises with provided solutions - The exercises at the end of each chapter let you practice what you’ve just learned. However, to make sure you get the most practice in the least time, these exercises start from applications that you can download from our website. This download also includes the solutions to the exercises so you can compare your solutions with the model solutions.
  • Complete applications and their code to study - To show you how all of the pieces of a PHP and MySQL application work together, this book presents the HTML, PHP, and MySQL code for 16 applications. As we see it, the only way to master PHP programming is to study the code in applications like these... but this is a missing ingredient in other books.

What's new in this edition

  • Coverage of PHP 8 enhancements like match expressions, constructor property promotion, and the nullsafe operator, all integrated into the text and not just tacked on to an appendix.
  • Updates throughout the entire book to conform to the latest best practices.

What software you need

XAMPP (Apache, MySQL, and PHP)

To run web applications that use PHP and MySQL, you need:

  • the Apache web server
  • the MySQL or MariaDB database server
  • PHP

All three of these can be downloaded and installed for free in a single download called XAMPP.

A text editor or an IDE

To edit your PHP code, you can use any text editor that you like. However, we recommend using an IDE (Integrated Development Environment) such as NetBeans that includes a text editor that’s designed for working with HTML, CSS, and PHP.

Besides allowing you to edit your text files, NetBeans makes it easier to run your applications. It can work with Xdebug to help you debug your applications. And chapter 1 presents a short introduction that gets you started with it.

One or more internet browsers

To test any web application, you need multiple web browsers. To start, we recommend that you test your applications using Google Chrome. In addition, you can use the browser that comes with your operating system (Edge for Windows and Safari for macOS).

Installation instructions provided in appendixes

To help you install these programs, the appendixes provide the website addresses and procedures that you’ll need for Windows and macOS.

Related books

HTML and CSS

Every PHP developer should have a copy of our HTML and CSS book. It will help you expand your HTML and CSS skills in a professional way whenever you have some extra time. It covers today’s best practices for using HTML and CSS. And it’s the best on-the-job reference available for HTML and CSS.

Modern JavaScript

If you want to learn how to provide client-side functionality for your web pages, our Modern JavaScript book shows how to use pure JavaScript to do that. To make learning as fast and easy as possible, this book skips confusing old features and jumps straight to the current features and best practices of modern JavaScript.

JavaScript and jQuery

If you need to learn jQuery, we recommend our JavaScript and jQuery book. This book is similar to Modern JavaScript in many ways, but it integrates coverage of jQuery, an influential JavaScript library that has been around since 2006 and is still used extensively in millions of websites.

MySQL

If you want to learn more about MySQL, our MySQL book expands on the MySQL material in our PHP book. It goes into more depth on subjects like querying, with more options and more examples. And it covers advanced subjects like stored procedures and database administration.

What people say about this book

"Awesome book. Murach’s PHP and MySQL reads like a learning book but is structured in a way that makes it an excellent reference manual. The left side explanation/right side code orientation took me a little time to warm up to but is actually a much more clean layout and works much better when you are referencing."
- Verified purchase at an online bookseller

“Excellent knowledge and insight for a small price! The table of contents is well written so you can pick a topic and jump right into exactly what you need.”
- Verified purchase at an online bookseller"Compared to the stack of other PHP/MySQL titles on the market, I found Murach to be one of the easiest and fastest books to teach the subject."
- Mike Riley, Dr. Dobb’s Online

"As a C# developer, I needed a book that would clear up the sometimes confusing syntax of PHP without requiring me to wade through a lot of concepts I already understood. This book does exactly that. Murach’s unique style of putting explanations on each left page and corresponding examples on each right page is ingeniously simple yet amazingly effective. The result is a very fast read. Also, the editing is superb. So far, I haven’t encountered any errors in the sample source code. Excellent book."
- Verified purchase at an online bookseller

“Great tutorials! Gotta have some real-world projects to be able to grasp the concepts, and this book delivers.”
- Verified purchase at an online bookseller

"Along with the great organization, ease of learning, and thorough coverage of the technologies and programming practice, this book is simply a pleasure to read. Any developer/techie/geek should enjoy it. A solid 5-star rating all the way."
- Jeff Salter, Developer, Sacramento, California

"This is my first Murach book and I love it so much I now want to go and buy their CSS and JavaScript books so I can learn even more about those languages."
- Verified purchase at an online bookseller

"Without a doubt, this book qualifies itself as a very practical book on learning PHP in the shortest time. I would thoroughly recommend this book to all budding PHP web developers out there, including ASP.NET developers who wish to diversify into PHP."
- Jason Ong, ASPNET World

"Truly a Beginner to Pro book. All the topics I needed to learn to get productive fast, and presented in a nice logical sequence. Definitely an A+++."
- Verified purchase at an online bookseller

View the table of contents for this book in a PDF: Table of Contents (PDF)

Click on any chapter title to display or hide its content.

Section 1 Get started fast with PHP and MySQL

Chapter 1 Introduction to web development with PHP

The architecture of a web application

How a client-server architecture works

How static web pages are processed

How dynamic web pages are processed

A survey of web application software

Highlights in the history of PHP

Highlights in the history of MySQL

The Product Discount application

The user interface

The HTML file

The CSS file

The PHP file

How to edit and test a PHP application

How to edit a PHP page with a text editor

How to start and stop Apache and MySQL on your own computer

How to deploy a PHP application

How to run a PHP application

How to test and debug a PHP page

How to view the source code for a web page

How to use NetBeans to develop a PHP application

How to work with PHP projects and files

How to edit and test a PHP application

How to import and configure a PHP project

Chapter 2 How to code a PHP application

Basic PHP skills

How to embed PHP in HTML

How to code comments and statements

The six PHP data types

How to declare variables and constants

How to get data from a request

How to use the built-in $_GET array

How to use the built-in $_POST array

When to use the HTTP GET and POST methods

How to work with data

How to code string expressions

How to code echo statements

How to code numeric expressions

How to use the compound assignment operators

How to use some built-in functions

How to use the filter_input() function

The Product Discount application

The user interface

The form in the HTML file

The PHP file

How to code control statements

How to code conditional expressions

How to code if statements

How to code while and for statements

How to pass control to another page

The Future Value application

The user interface

The code for the indexphp file

The code for the display_resultsphp file

How to use the PHP documentation

How to access the PHP manual

How to find the documentation you need

Chapter 3 Introduction to relational databases and MySQL

An introduction to relational databases

How a database table is organized

How the tables in a relational database are related

How the columns in a table are defined

The SQL statements for data manipulation

How to select data from a single table

How to select data from multiple tables

How to insert, update, and delete data

An introduction to MySQL

What MySQL provides

Two ways to work with MySQL

How to use phpMyAdmin

How to start phpMyAdmin

How to log in, log out, and change your password

How to import and run a SQL script that creates a database

How to review the data and structure of a table

How to run SQL statements

How to create users with limited privileges

Chapter 4 How to use PHP with a MySQL database

How to connect to a database and handle exceptions

How to connect to a database

How to handle exceptions

How to get and modify data

How to execute SELECT statements

How to work with the first row of a result set

How to work with all the rows of a result set

How to execute INSERT, UPDATE, and DELETE statements

The Product Viewer application

The user interface

The code

The Product Manager application

The user interface

The code

Chapter 5 How to use the MVC pattern to organize your code

How to use the MVC pattern

An introduction to the MVC pattern

How to code functions

How to redirect requests

How to use the Post-Redirect-Get pattern

The Product Manager application

The user interface

The model

The controller

The view

The Product Catalog application

The user interface

The model

The controller

The view

Chapter 6 How to test and debug a PHP application

An introduction to testing and debugging

Typical test phases for a PHP application

The three types of errors that can occur

Common PHP errors

An easy way to trace the execution of your PHP code

How to debug with Xdebug and NetBeans

How to set and remove breakpoints

How to step through code

How to inspect variables

How to inspect the stack trace

Section 2 Master PHP programming

Chapter 7 How to work with form data

How to get data from a form

How to get data from text boxes, password boxes, and hidden fields

How to get data from a radio button

How to get data from a check box

How to get data from an array of check boxes

How to get data from a drop-down list

How to get data from a list box

How to get data from a text area

How to display data on a web page

How to format special characters

How to format line breaks

How to display data with echo and print statements

Chapter 8 How to code control statements

How to code conditional expressions

How to use the equality and identity operators

How to use the relational operators

How to use the logical operators

How to code the selection structures

How to code if statements with else clauses

How to code if statements with else if clauses

How to use the conditional operator

How to use the null coalescing operators

How to code switch statements

How to code match expressions

How to use a switch statement in the controller

How to code the iteration structures

How to code while loops

How to code do-while loops

How to code for loops

How to use the break and continue statements

Chapter 9 How to work with strings and numbers

How to work with strings

How to create strings

How to use escape sequences

How to work with string length and substrings

How to search a string

How to modify strings

How to convert strings to and from arrays

How to convert strings to and from ASCII values

How to compare strings

How to work with numbers

How to assign integers

How to assign floating-point values

How to use the math functions

How to generate random numbers

Other skills for working with strings and numbers

How to use the sprintf() function to format strings and numbers

How to convert strings to numbers

Chapter 10 How to work with dates

Two ways to work with dates and times

An introduction to timestamps

An introduction to DateTime objects

How to use objects to work with dates

How to use the DateTime object

How to modify and validate a DateTime object

How to format a DateTime object

How to use the DateInterval and DateTime objects together

Examples of working with DateTime objects

Chapter 11 How to create and use arrays

How to create and use an array

How to create an array

How to add and delete elements

How to work with variable substitution

How to use for loops to work with arrays

How to create and use an associative array

How to create an associative array

How to add and delete elements

How to work with variable substitution

More skills for working with arrays

How to use foreach loops to work with arrays

How to work with the spread operator

How to use functions to work with arrays

How to fill, merge, slice, and splice arrays

How to check if a variable is an array

How to work with queues and stacks

How to get the sum and product of elements

 How to search arrays

How to sort arrays

 How to modify arrays

How to work with arrays of arrays

Understanding an array of arrays

How to create and use an array of arrays

The Task List Manager application

The user interface

The code for the controller

The code for the view

Chapter 12 How to work with cookies and sessions

How to work with cookies

An introduction to cookies

How to set and get a cookie

How to enable or disable cookies

How to work with sessions

Why session tracking is difficult with HTTP

How session tracking works in PHP

How to start a session

How to set and get session variables

How to manage a session

How to end a session

The Shopping Cart application

The user interface

The controller

The model

The Add Item view

The Cart view

Chapter 13 How to create and use functions

Basic skills for working with functions

How to create a function

How to call a function

How to pass arguments by value and by reference

How variable scope works

How to use optional parameters

How to use named arguments

How to work with type declarations

How to use variable-length parameter lists

How to create and use a library of functions

A library of functions

How to set the include path

How function scope works

How to create and use namespaces

Advanced skills for working with functions

How to work with variable functions and callbacks

How to work with anonymous functions

How to work with arrow functions

How to work with closures

The Shopping Cart application

The user interface

The model

The controller

The view

Chapter 14 How to create and use objects

How to create and use classes

The code for the Category class

The code for the Product class

How to code properties

How to code constructors and destructors

How to use constructor property promotion

How to code methods

How to create and use objects

How to code class constants, properties, and methods

How to code class constants

How to code static properties and methods

How to work with enums

How to work with pure enums

How to work with backed enums

The object-oriented Product Manager application

The user interface

The model

The controller

The view

Additional skills for working with objects

How to loop through an object’s properties

How to clone and compare objects

How to inspect an object

How to work with inheritance

How to inherit a class

How to use the protected access modifier

How to create abstract classes and methods

How to create final classes, methods, and constants

How to work with interfaces

Chapter 15 How to use regular expressions, handle exceptions, and validate data

How to use regular expressions

How to create and use regular expressions

How to match characters

How to use the character class

How to create complex patterns

How to use look-ahead assertions

How to use a multiline regular expression

How to use a global regular expression

How to replace a regular expression with a string

How to split a string on a regular expression

Regular expressions for data validation

How to handle exceptions and errors

How to create and throw exceptions

How to catch exceptions

How to catch errors

The Registration application

The user interface

The file structure

The model

The controller

The view

A long version of the Registration application

Section 3 Master MySQL programming

Chapter 16 How to design a database

How to design a data structure

The basic steps for designing a data structure

How to identify the data elements

How to subdivide the data elements

How to identify the tables and assign columns

How to identify the primary and foreign keys

How to enforce the relationships between tables

How normalization works

How to identify the columns to be indexed

How to normalize a data structure

The seven normal forms

How to apply the first normal form

How to apply the second normal form

How to apply the third normal form

When and how to denormalize a data structure

Chapter 17 How to use SQL to create a database

How to work with databases

How to create a database

How to select a database

How to drop a database

How to work with tables

An introduction to MySQL data types

How to create a table

How to code a primary key

How to code a foreign key constraint

How to alter a table

How to drop a table

How to work with indexes

How to create an index

How to drop an index

How to work with users and privileges

A summary of privileges

How to work with users

How to grant privileges

How to revoke privileges

How to view privileges

Other skills for creating a database

How to load data from text files

How to dump a database to a SQL script

The script for the Guitar Shop database

Chapter 18 How to use SQL to work with a database

How to select data from a single table

How to select columns from a table

How to use an alias for a column

How to select rows with a LIMIT clause

How to select rows with a WHERE clause

How to use the logical operators

How to use the IS NULL operator

How to use the LIKE operator

How to sort rows with an ORDER BY clause

How to select data from multiple tables

How to code an inner join

When and how to use table aliases

How to code summary queries

How to code aggregate functions

How to group queries by column

How to code subqueries

Where to use subqueries

How to code correlated subqueries

How to insert, update, and delete rows

How to insert rows

How to update rows

How to delete rows

Chapter 19 Professional PHP for working with MySQL

Three ways to use PHP to work with MySQL

PDO (PHP Data Objects)

PHP’s mysqli extension

PHP’s MySQL extension

How to work with PDO

How to connect to a database

How to select data

How to insert, update, and delete data

How to work with prepared statements

How to set the error mode for PDO

A model in PDO

How to work with mysqli

How to connect to a database

How to select data

How to insert, update, and delete data

How to work with prepared statements

The object-oriented style compared to the procedural style

A model in mysqli

Chapter 20 A database-driven website

How to work with large text columns

A simple content management system

How to add HTML tags to text

The include files for the Guitar Shop website

The Home page

The directory structure

The utility files

The view files

The Product Catalog application

The user interface

The controller

The view

The Product Manager application

The user interface

The controller

The view

Section 4 Master the advanced skills for building websites

Chapter 21 How to create secure websites

How to use a secure connection

An introduction to secure connections

How SSL authentication works

How to get a digital secure certificate

How to request a secure connection

How to redirect to a secure connection

How to use authentication

Three types of authentication

How to store and validate a password

How to use form-based authentication

Chapter 22 How to work with files, uploads, and images

How to work with files

How to get a directory listing

How to read and write an entire file

How to read and write part of a file

How to copy, rename, and delete a file

How to upload a file

HTML for uploading a file

PHP for working with an uploaded file

How to work with images

How to get information about an image

How to read and write images

How to resize an image

How to work with transparency

The Image Upload application

The user interface

The utility files

The controller

The view

Chapter 23 An eCommerce website

An introduction to the website

Prototyping and stepwise refinement

The directory structure of the website

The user interface for end users

The Catalog application

The Cart application

The Checkout and Account applications

The My Account page

The user interface for administrators

The Admin Login and Admin Menu pages

The Product Manager application

The Category Manager application

The Order Manager application

The Account Manager application

Appendix

Appendix A How to set up Windows for this book

How to install Chrome and Notepad++

How to install the Chrome browser

How to install Notepad++

How to install and configure XAMPP

How to install XAMPP

How to set the default time zone for PHP

How to start and stop the Apache and MySQL servers

How to configure phpMyAdmin

How to install the book applications and databases

How to install the source code for this book

How to create and restore the databases

How to install NetBeans and Xdebug

How to install NetBeans

How to install Xdebug

Appendix B How to set up macOS for this book

How to install Chrome and Atom

How to install the Chrome browser

How to install Atom

How to install and configure XAMPP

How to install XAMPP

How to set the default time zone for PHP

How to start and stop the Apache and MySQL servers

How to configure phpMyAdmin

How to install the book applications and databases

How to install the source code for this book

How to create and restore the databases

How to install NetBeans and Xdebug

How to install NetBeans

How to install Xdebug

Sample chapters

Chapter 1: Introduction to web development with PHP

This chapter gives you the background that will get you off to a fast start with PHP. It explains how web programming with PHP works and shows you all the code (HTML, CSS, and PHP) for an application so you can see how the pieces fit together. Furthermore, it demonstrates the software tools you’ll use to create PHP applications. When you’re done, you’ll be ready to start programming with PHP.

Chapter 1 PDF Download Now

Book applications and exercises

This download includes:

  • The PHP source code and MySQL scripts for all the applications that are presented in the book, including the Guitar Shop e-commerce application
  • The starting source code for the exercises in the book
  • Solutions to the book exercises so you can check your work

The appendixes in the book show how to install and use these files on Windows and macOS.

Zip file for any system Download Now

On this page, we’ll be posting answers to the questions that come up most often about this book. So if you have any questions that you haven’t found answered here at our site, please e-mail us. Thanks!

To view the corrections for this book in a PDF, just click on this link: View the corrections

Then, if you find any other errors, please email us so we can correct them in the next printing of the book. Thank you!

There are no reviews for this product yet.

To leave a review, please log in to your account.     Log In Here

Our Ironclad Guarantee

You must be satisfied. Try our print books for 30 days or our eBooks for 14 days. If they aren't the best you've ever used, you can return the books or cancel the eBooks for a prompt refund. No questions asked!

Contact Murach Books

For orders and customer service:

1-800-221-5528

Weekdays, 8 to 4 Pacific Time

College Instructors

If you're a college instructor who would like to consider a book for a course, please visit our website for instructors to learn how to get a complimentary review copy and the full set of instructional materials.