Skip to main content
main-content
Top

About this book

Introductory textbook covering all the main features of the 'web programming' languages PHP and MySQL together with detailed examples that will enable readers (whether students on a taught course or independent learners) to use them to create their own applications or understand existing ones. A particular focus is the use of PHP to generate MySQL commands from a script as it is executed.
Each chapter includes aims, a summary and practical exercises (with solutions) to support learning. Chapters are designed to stand alone as far as possible, so that they can be studied independently of the rest of the text by those with some previous knowledge of the languages. There is a comprehensive glossary of technical terms, together with extensive appendices for quick reference of language features.

Table of Contents

Chapter 1. Introduction

Abstract
After reading this chapter you should be able to:
  • understand the value of using the PHP language to enable non-static information to be included on webpages, especially information retrieved from a relational database using the popular database query language MySQL
  • understand how a web browser processes an HTML file and how PHP files are processed
  • check that your web server is able to run PHP scripts
  • understand how a valuable improvement to a webpage can sometimes be made using only a single line of PHP.
Max Bramer

Chapter 2. PHP Fundamentals

Abstract
After reading this chapter you should be able to:
  • describe the basic structure of a PHP script or scripting block
  • understand how a PHP file containing a mixture of HTML and PHP is processed
  • discriminate between valid and invalid names for variables and functions
  • explain the similarities and differences between a scalar variable and an array
  • explain the differences between strings enclosed in single and double quotes and the use of escape sequences in strings
  • explain the importance of system functions to programming in PHP
Max Bramer

Chapter 3. The PHP Language: Types of Statement

Abstract
After reading this chapter you should be able to:
  • understand seven of the most important statements in the PHP language
  • use those statements to construct simple PHP scripts
  • evaluate a complex arithmetic, string or logical expression
  • understand how PHP Print statements differ from those in conventional programming languages
  • understand how PHP handles and prints logical values
  • understand different types of conditional statement
  • understand the three types of looping statement available in PHP and the difference between them
  • understand the use of the ‘include’ statement to ‘include and evaluate’ the contents of a PHP file while a PHP script is executing.
Max Bramer

Chapter 4. More About Arrays

Abstract
After reading this chapter you should be able to:
  • use arrays when writing PHP scripts, especially in conjunction with the Foreach statement
  • use the various sort functions available in PHP and understand the differences between them
  • distinguish between indexed arrays and associative arrays
  • use the explode and implode functions to convert strings with internal separator characters, such as commas, into arrays and vice versa.
Max Bramer

Chapter 5. Some Important Functions

Abstract
After reading this chapter you should be able to:
  • understand and use the most important functions available in PHP for manipulating both numbers and strings
  • use the date function to generate the date and/or time in any of a wide variety of formats
  • understand the system functions header, die and echo
  • obtain detailed information about the configuration of the version of PHP you are using, including the version number.
Max Bramer

Chapter 6. Formatted Print Functions

Abstract
After reading this chapter you should be able to:
  • use the printf function to output numbers in a structured form
  • understand the meaning of a format string and the various kinds of specifier
  • use the sprintf function to assign a formatted string to a variable
Max Bramer

Chapter 7. Using Files

Abstract
After reading this chapter you should be able to:
  • understand the organisation of the files making up a website in a hierarchy of directories and sub-directories
  • understand the concepts associated with the creation and use of text files
  • understand the principles of file protection
  • use the many functions provided in PHP to manipulate files and directories.
Max Bramer

Chapter 8. User-Defined Functions

Abstract
After reading this chapter you should be able to:
  • create and use your own user-defined functions
  • create and use a personal function library
  • understand the difference between passing arguments by value and by reference
  • understand how to give an argument of a function a default value.
Max Bramer

Chapter 9. Passing Variables to a PHP Script I

Abstract
After reading this chapter you should be able to:
  • understand in detail the components of a web form
  • write a webform of your own using a combination of HTML and PHP function calls
Max Bramer

Chapter 10. Passing Variables to a PHP Script II

Abstract
After reading this chapter you should be able to:
  • write the PHP statements that enable values sent by any of the form objects described in Chap. 9 to be used in a destination page
  • send variable values to a destination page using an extended URL and write PHP statements to use the values sent in the destination page
  • use session variables to pass values around the PHP scripts in a large website.
Max Bramer

Chapter 11. PHP in Action: Managing a Members’ Area

Abstract
After reading this chapter you should be able to:
  • use the material introduced earlier in the book to write useful PHP scripts, especially to deal with information sent from a webform and to create, read and analyse the content of text files.
Max Bramer

Chapter 12. Using a MySQL Database I

Abstract
After reading this chapter you should be able to:
  • understand the principal features of a MySQL database and database management system
  • use the MySQL commands needed to create a MySQL database, insert a record into a table, delete and update records and change the structure of a table.
Max Bramer

Chapter 13. Using a MySQL Database II

Abstract
After reading this chapter you should be able to:
  • use the MySQL commands needed to extract information from a database table, combine information from different tables, rename a table and delete either a table or a database
  • understand the different types of ‘join’ operation available in MySQL
  • find the version of MySQL that you are using.
Max Bramer

Chapter 14. Creating and Updating MySQL Tables

Abstract
After reading this chapter you should be able to:
  • use a MySQL command to create a database table
  • understand the various data types available in MySQL
  • construct an appropriate column definition for each field in a table
  • copy the structure and/or the contents of one table to another
  • find the structure of a table
change the structure, name and field specification of a table.
Max Bramer

Chapter 15. Using a PHP Script to Manage a MySQL Database

Abstract
After reading this chapter you should be able to:
  • use PHP to manage a MySQL database
  • use PHP to send MySQL commands to a MySQL server
  • use PHP to display the results of a MySQL SELECT, SHOW or DESCRIBE command in tabular form
  • use PHP to determine the number of rows of a table affected by a MySQL INSERT, UPDATE, REPLACE or DELETE command
  • understand the difference between PHP functions with names prefixed with mysql_ and those prefixed with mysqli_
  • display the version of MySQL you are using.
Max Bramer

Chapter 16. PHP in Action: Converting Data between Text Files and Database Tables

Abstract
After reading this chapter you should be able to:
  • understand issues relating to data cleaning
  • use PHP to take data stored in a text file, clean it and convert it to a database table
  • export data from a database table to a text file for archive purposes
  • restore a database table from a backup held as a text file.
Max Bramer

Chapter 17. Using PHP to View and Edit Database Tables

Abstract
After reading this chapter you should be able to:
  • use PHP to find the tables in the current database and display the contents and/or structure of each one
  • use PHP to create a visual table editing facility.
Max Bramer

Chapter 18. PHP in Action: Maintaining a Membership List

Abstract
After reading this chapter you should be able to:
  • use PHP in conjunction with MySQL to maintain an organisation’s membership records
  • write a PHP script to register a user, log into a password protected website, create a password, issue a password reminder and manage a table of members
  • write PHP statements to send an email from a PHP script.
Max Bramer

Chapter 19. Appendices

Abstract
an angle measured in degrees
Max Bramer
Additional information