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!
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 way the pros do. In fact, you’ll create a database-driven website that implements the MVC pattern in the first 6 chapters! Then, the rest of the chapters show you how to build out your PHP and MySQL skills to the professional level.
Go to our instructor’s site to learn more about the latest edition of 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."
This book is for anyone who wants to learn how to build and maintain websites that use PHP and MySQL. If you have some programming experience, you’ll move through this book more quickly. But because of its self-paced approach, this book also works for beginning programmers.
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, you can read Murach’s HTML5 and CSS3.
This book gets you started with PHP and MySQL as quickly as possible and then builds out your skills in a professional way. To present the whole array of PHP and MySQL skills in a manageable progression, this book is divided into four sections.
This section is designed to get you off to a fast start whether or not you have any programming experience. So 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 and beginners work at a pace that’s comfortable for absorbing all of the new information. Then, 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 important, you’ll actually be able to build database-driven web applications of your own!
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 arrays, functions, regular expressions, exception handling, libraries, your own objects…and more! 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.
In this section, you’ll expand your MySQL and PHP skills to include the skills you need for building full-fledged database-driven web applications. That includes:
The last section in this book rounds out your web development skills by showing you how to:
These are the skills you need to ensure that your web applications come across as trustworthy, reliable, and fully professional to your visitors. Then, the last chapter in this section shows how to put all your skills together in an e-commerce website.
Like all our books, this one has features that you won’t find in competing books. 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.
To run web applications that use PHP and MySQL, you need:
All three of these can be downloaded and installed for free in a single download called XAMPP.
To edit your PHP code, you can use any text editor that you like. However, a text editor that includes syntax coloring and auto-formatting will help you develop applications more quickly and with fewer errors. That’s why we recommend:
Both are available for free, and both can be used for entering and editing HTML, CSS, and PHP code.
To test any web application, you need multiple web browsers. To start, you can use the browser that comes with your computer: Internet Explorer for Windows systems and Safari for Macs. But we also recommend that you test your applications using Google Chrome and Mozilla Firefox, and both are available for free.
If you would like to use an Integrated Development Environment for PHP programming, we recommend the NetBeans IDE. It includes a text editor that lets you enter and edit code. It provides an easy way for you to run your applications. And it provides special tools that help you debug your applications.
To help you install these products, the appendixes provide the website addresses and procedures that you’ll need for both Windows and Mac OS systems. In addition, chapter 1 provides a quick guide to using Notepad++ and NetBeans.
Murach’s MySQL is the perfect companion book to our PHP book. This 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. It goes into more breadth by covering new subjects, like how to use stored programs and do database administration tasks. And it’s the perfect MySQL desk reference.
Murach’s HTML5 and CSS3 is another book that every PHP developer should have. 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 HTML5 and CSS3. And it’s the best on-the-job reference available for HTML and CSS.
Murach’s JavaScript and jQuery is a third book that every PHP developer should have. It teaches you how to write client-side code for your web pages to enhance the user experience. And it is another great on-the-job reference.
"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."
- Posted 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
"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. I frequently scan the sample page first and only read the explanation page when I need further clarification. However, the explanation page is always there if you need it. 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."
- Posted at an online bookseller
"This is my first Murach book and I love it so much I now want to go and buy their CSS, JavaScript, and C++ books so I can learn even more about those languages."
- Posted 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
"Murach books are always excellent. When I started working with PHP, I was hoping they would release a PHP book. I am thrilled with this book…. It is an excellent learning book, as it walks through all features, but it also is an excellent reference book for advanced programmers. I highly recommend this for PHP and MySQL programming."
- Posted 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. It effectively compresses the key amounts of information required to understand PHP programming and competently execute a solid PHP application from scratch."
- Mike Riley, Dr. Dobb’s Online
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.
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 user interface
The HTML file
The CSS file
The PHP file
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 work with PHP projects and files
How to edit and test a PHP application
How to import and configure a PHP project
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 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 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
The user interface
The form in the HTML file
The PHP file
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 user interface
The code for the index.php file
The code for the display_results.php file
How to access the PHP manual
How to find the documentation you need
How a database table is organized
How the tables in a relational database are related
How the columns in a table are defined
How to select data from a single table
How to select data from multiple tables
How to insert, update, and delete data
What MySQL provides
Two ways to work with MySQL
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
How to connect to a MySQL database
How to execute SELECT statements
How to execute INSERT, UPDATE, and DELETE statements
How to use a try/catch statement to handle exceptions
How to work with arrays
How to get the data from the first row of a result set
How to get the data from all the rows of a result set
The user interface
The code
The user interface
The code
An introduction to the MVC pattern
How to code functions
How to redirect requests
The user interface
The model
The controller
The view
The user interface
The model
The controller
The view
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 set and remove breakpoints
How to step through code
How to inspect variables
How to inspect the stack trace
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 format special characters
How to format line breaks
How to display data with echo and print statements
How to use the equality and identity operators
How to use the relational operators
How to use the logical operators
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 code switch statements
How to use a switch statement in the controller
How to code while loops
How to code do-while loops
How to code for loops
How to use the break and continue statements
How to create strings
How to use escape sequences
How to work with string length and substrings
How to search a string
How to replace part of 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 assign integers
How to assign floating-point values
How to use the math functions
How to generate random numbers
How to use the sprintf function to format strings and numbers
How to convert strings to numbers
How to create and format timestamps
How to work with timestamps
How to use the strtotime function
Examples of working with timestamps
How to use the DateTime class
How to use the DateInterval class
How to use the DateInterval and DateTime classes together
Examples of working with DateTime objects
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 an associative array
How to add and delete elements
How to work with variable substitution
How to use foreach loops to work with arrays
How to fill, merge, slice, and splice arrays
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
Understanding an array of arrays
How to create and use an array of arrays
The user interface
The code for the controller
The code for the view
An introduction to cookies
How to set and get a cookie
How to enable or disable cookies
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 end a session
How to manage a session
The user interface
The controller
The model
The Add Item view
The Cart view
How to create and call a function
How to pass arguments by value and by reference
How variable scope works
How to provide default values for parameters
How to use variable-length parameter lists
A library of functions
How to set the include path
How function scope works
How to create and use namespaces
How to work with variable functions and callbacks
How to work with anonymous functions
How to work with closures
The user interface
The model
The controller
The view
The code for the Category class
The code for the Product class
How to code properties
How to code constructors and destructors
How to code methods
How to create and use objects
How to code class constants
How to code static properties and methods
The user interface
The model
The controller
The view
How to loop through an object’s properties
How to clone and compare objects
How to inspect an object
How to inherit a class
How to use the protected access modifier
How to create abstract classes and methods
How to create final classes and methods
How to work with interfaces
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 create and throw exceptions
How to use the try-catch statement
The user interface
The file structure
The model
The controller
The view
A long version of the Registration application
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
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
An introduction to MySQL Workbench
How to use MySQL Workbench to create database diagrams
How to create a database
How to select a database
How to drop a database
An introduction to MySQL data types
How to create a table
How to code a primary key
How to alter a table
How to drop a table
How to create an index
How to drop an index
A summary of privileges
How to create, rename, and drop users
How to grant privileges
How to revoke privileges
How to view privileges
How to load data from text files
How to dump a database to a SQL script
The script for the Guitar Shop database
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 code an inner join
When and how to use table aliases
How to code aggregate functions
How to group queries by column
Where to use subqueries
How to code correlated subqueries
How to insert rows
How to update rows
How to delete rows
PDO (PHP Data Objects)
PHP’s mysqli extension
PHP’s MySQL extension
How to work with prepared statements
How to set the error mode for PDO
A model in PDO
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
A simple content management system
How to add HTML tags to text
The home page
The directory structure
The utility files
The view files
The user interface
The controller
The view
The user interface
The controller
The view
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
Three types of authentication
How to store and validate a password
How to use form-based authentication
How to use basic authentication
How to encrypt and decrypt data
A class for storing encrypted data
How email works
How to install the PEAR Mail package
How to set up a test email account
How to use PEAR Mail to send an email
A helper function for sending an email
How to use the helper function to send an email
How to enable the cURL library
How to use cURL to connect to another web server
How to use an API provided by another server
The user interface
The controller
Search view
Email view
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 read and write CSV data
How to copy, rename, and delete a file
HTML for uploading a file
PHP for working with an uploaded file
How to get information about an image
How to read and write images
How to resize an image
How to work with transparency
The user interface
The utility files
The controller
The view
Prototyping and stepwise refinement
The directory structure of the web site
The Catalog application
The Cart application
The Checkout and Account applications
The My Account page
The Admin Login and Admin Menu pages
The Product Manager application
The Category Manager application
The Order Manager application
The Account Manager application
How to install the Firefox browser
How to install Notepad++
How to install XAMPP
How to configure phpMyAdmin
How to install NetBeans
How to configure xDebug
How to install the source code for this book
How to create and restore the databases
How to install the Firefox browser
How to install TextWrangler
How to install XAMPP
How to configure phpMyAdmin
How to install NetBeans
How to install xDebug
How to install the source code for this book
How to create and restore the databases
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. It shows you all the code (HTML, CSS, and PHP) for a Product Discount application so you can see how all the pieces fit together. And it demonstrates the software tools you’ll use to create PHP applications. When you’re done, you’ll be ready to start in on the details of PHP programming.
Chapter 1 PDF (1.5Mb) Download Now
This download includes:
The appendixes in the book show how to install and use these files on both Windows and Mac OS systems.
Exe file for Windows (14.7Mb) Download Now
Zip file for any system (14.6Mb) Download Now
Below are the answers to the questions that have come up most often about this book. If you have any questions that aren’t answered here, please email us. Thanks!
This book was developed using version 1.7.2 of XAMPP. Some newer versions of XAMPP such as 1.7.4 have stricter settings for error reporting.
The easiest way to fix this problem is to modify the php.ini that’s in the c:\xampp\php folder so it uses the same error reporting settings as version 1.7.2. To do that, open the php.ini file in a text editor, search for “error_reporting”, and change the error_reporting setting so it looks like this:
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
Then, use XAMPP to stop and restart the Apache server. Once you do this, the “undefined variable” error should be fixed for all of the downloadable applications in this book.
If you don’t want to change the error_reporting setting, you can modify the code so it complies with the stricter error reporting setting. To do that for the echo statements that are in the Future Value application, you can add an if statement to check whether each variable is declared before you attempt to use it. For example, to fix the first error that occurs for this application, you can use code like this:
value=""/>
Similarly, for the Guitar Shop application, you can check the indexes of arrays to make sure they exist like this:
if (isset($_GET[‘category_id’])) {
$category_id = $_GET[‘category_id’];
}
Version 1.7.3 of XAMPP for Mac OS doesn’t install a digital certificate on the Apache server by default. As a result, you must install this certificate yourself. To do that, you can start a Terminal window and run this command:
sudo /Applications/XAMPP/xamppfiles/xampp enablessl
This book was developed using version 1.7.2 of XAMPP, which runs without any bugs under Windows 7. Unfortunately, version 1.7.4 of XAMPP has some bugs when running under Windows 7. If you install this version, you may get an error message when you start the Control Panel that says:
XAMPP Component Status Check Failure[3].
At this point, you can still start the Apache and MySQL servers, and they will run correctly. However, you won’t be able to use the Admin button for MySQL to start phpMyAdmin. As a result, you’ll need to start phpMyAdmin manually by entering its URL in the browser as described in chapter 3.
The easiest way to fix this problem (and to set up your computer to work exactly as shown in our book) is to install version 1.7.2 of XAMPP. To do that, you can follow these directions:
The procedure for downloading NotePad++ has changed since this book was written. The new procedure follows.
To view the corrections for this book in a PDF, just click on this link: View the corrections
This includes coverage of problems that have arisen due to later releases of the required software.
Then, if you find any other errors, please email us, so we can correct them in the next printing of the book. Thank you!
For orders and customer service:
1-800-221-5528
Weekdays, 8 to 4 Pacific Time
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.