|
Introduction |
|
||
|
|
|||
|
|
|||
|
|
Overview |
|
|
|
|
|||
|
|
|||
|
|
This book, like all of my books, is based on the learn-by-doing principle because I believe simply reading about a subject is not the best way to learn. After all, you don't read about putting together a jigsaw puzzle, you put the puzzle together yourself! Programming is the same way. You must actually run some programs in order to really understand the concepts. |
|
|
|
|
||
|
|
PHP shows how to create applications organically. In this book, you start with simple programs and gradually add features. |
|
|
|
||
|
|
The technical topics are covered in a straightforward, non-technical manner which allows you to quickly understand the fundamental principles. After the main topic of each chapter is introduced, subtopics are explored in their own sections. Each section has its own PHP examples. |
|
|
|
|
|
|
The Interlude chapters that are sprinkled throughout the books should appeal to hard-core programmers. The goal for the Interlude chapters is to show code use, even if all the functions used were not explained in detail in the chapter text. |
|
Who Should Use This Book? |
|
|||
|
|
||||
|
|
||||
|
|
If you're new to programming, this book is perfect for you. Chapters 4 and 5 provide an introduction to the PHP language. And Chapter 7 provides an introduction to databases. After reading those chapters, feel free to pick from the rest—your knowledge base will be broad enough to understand any other topics we cover in this book. |
|
||
|
|
||||
|
|
||||
|
|
Experienced programmers will want to concentrate on the more complex chapters. For example, Chapter 9 covers pattern matching, which frequently confuses even advanced programmers. |
|
||
|
|
||||
|
|
||||
|
|
The approach used in this book is designed to serve a broad range of readers from novice to advanced. If you've never programmed before, the learn-by-doing approach will help you move quickly and easily though this book. If you have programming experience, you'll find plenty of material to refine and enhance what you already know, and to give you a solid understanding of how PHP works. |
|
||
|
What Do I Need? |
|
||
|
|
|||
|
|
You need a computer running Linux; everything else can be found on the CD-ROM that comes with this book. |
|
|
|
How to Use This Book |
|
|
|
||
|
|
You have several ways that you can use this book. One obvious method is to begin at the first page and proceed in sequential order until the last. Most beginning programmers will probably want to use this method, and the book is specifically designed so that each chapter builds on the last. Alternatively, you can focus on the Interlude chapters and skip back to the technical chapters when you come across unfamiliar concepts. |
|
|
|
||||
|
|
Tip |
|
It is critical to read through the PHP Function List ( Appendix D) at least once before starting any major project. Otherwise, you could spend hours developing a function that already exists. |
|
|
Code Listings |
|
|
|
||
|
|
Many readers prefer to type in most of the example code by hand; this helps them focus on the code one line at a time. Another good approach is to work through an example in a chapter, close the book, and enter it by hand from memory. The struggle that you experience helps to deepen your understanding. Remember, getting lost can help you learn to find your way. |
|
|
|
||
|
|
If you're lazy, can't type fast, or are prone to wrist pains like some of my friends, you can copy the listings from the CD-ROM that is included at the back of this book. Each listing on the CD-ROM has a listing header like this: |
|
|
|
||
|
|
Listing 0.1: example.php3—This is a sample listing header |
|
|
|
||
|
|
// This is a sample program line. |
|
|
|
|
|
|
After each example, experiment a little and see what happens. Change a few things, or add a couple, and change the code a bit. This will help you enjoy the learning experience more. The most important attribute of a successful learning experience is fun. If it is fun and you enjoy it, you will stay with it longer. |
|
Conventions |
|
|
|
||
|
|
The following conventions are used in this book: |
|
|
|
||||
|
|
• |
|
Code line, functions, variable names, and any text you see onscreen appear in a special monospace typeface. |
|
|
|
||||
|
|
• |
|
Filenames are also set in a monospace typeface. |
|
|
|
||||
|
|
• |
|
New terms are in italic. |
|
|
|
||||
|
|
• |
|
Case is very important in PHP programming. Always pay attention to uppercase and lowercase in variable and function names. |
|
|
|
||||
|
|
• |
|
If you are required to type text, the text you must type will appear in boldface. For example, "Type ./mysqlshow." Usually, however, the line is set off by itself in a monospace typeface, as shown in the following example: |
|
|
|
||
|
|
./mysqlshow |
|
|
|
|||
|
|
• |
|
Commands and keywords are set in boldface. |
|
Overview |
|
|
|
||
|
|
C hapter 1, "What Is PHP?," provides a description of PHP, how it integrates into the Apache Web server, and which tasks it can perform. Chapter 2, "Installing PHP," shows how to compile the MySQL database and PHP as an Apache Web server module with support for ODBC, XML, pattern matching, and MySQL. |
|
|
|
||
|
|
The next two chapters concentrate on the technical details of the PHP programming language. Chapter 3, "Manipulating Data within PHP," covers variables, literal values, and the operators that affect them. Chapter 4, "Controlling Your Programs," discusses expressions, statements, and functions. |
|
|
|
||
|
|
||
|
|
C hapter 5, "Interlude One—Connecting to a Database," puts the PHP language into perspective by using PHP to connect to the MySQL database. This chapter is the precursor for information found in Chapter 6, "Databases and SQL." Basic database concepts, such as tables and records are introduced in Chapter 6. Additionally, a data definition and data manipulation language called SQL (or Structured Query Language) is discussed. |
|
|
|
||
|
|
||
|
|
C hapter 7, "Interlude Two—Maintaining a List," shows how to integrate PHP and SQL to maintain a database table of month names. And Chapter 8, "phpMyAdmin—An Open Source Front End to MySQL," looks at an open source application that provides the ability to examine and change any MySQL database. |
|
|
|
||
|
|
||
|
|
C hapters 9, "Pattern Matching," and 10, "Object Orientation," cover further technical details about the PHP language. Pattern matching is the ability to find, and optionally replace, text. Object-oriented programming lets data and functions be stored together. Actually, object-oriented programming is more involved than that simple definition, but you can read Chapter 10 for the details. |
|
|
|
||
|
|
||
|
|
C hapter 11, "Interlude Three—Creating an HTML Module," offers a break from technical terms by developing a method to display HTML from inside PHP scripts. |
|
|
|
||||
|
|
The next several chapters return to more of a teaching mode. Chapter 12, "What is CGI?," looks at the underpinnings of the Web server's relationship to programs that are executed in response to Web browser requests. Even though PHP (in this book) is an integral part of the Apache Web server, it follows CGI rules. Chapter 13, "Authentication," shows how to know your Web visitors a little better. The basic techniques available to challenge users with userid and passwords are covered. |
|
||
|
|
||||
|
|
||||
|
|
C hapter 14, "Real-World SQL," talks about SQL in more depth. The different relationships between tables are covered, as well as the concept of Referential Integrity. Chapter 15, "Interlude Four: Managing Concurrent Access," uses the PHPLIB module to authenticate users and prevent more than one user from changing a record at a time. |
|
||
|
|
||||
|
|
||||
|
|
C hapters 16 and 17 look at XML. First, Chapter 16, "XML," provides insight about the differences and similarities of XML and HTML. The topic of Document Type Definitions (or DTDs) is covered. Chapter 17, " Processing XML with PHP," shows how to parse XML (that is, read and understand its tags) and move the information from within XML into PHP variables. |
|
||
|
|
||||
|
|
||||
|
|
A ppendix A, "Internet Resources," lists several types of resources available through the Internet, including mailing lists and Web sites. Appendix B, "The ASCII Table," shows you all of the ASCII codes and their corresponding characters. Appendix C, "SQL Reference," provides a quick list of SQL statements, operators, and functions. Appendix D, "PHP Function List," contains a list of the many functions of PHP in alphabetical order. Appendix E, "What's on the CD-ROM?", describes the contents of the CD. |
|
||
|
Acknowledgments |
|
|||||
|
|
||||||
|
|
I'd like to thank all of the people at McGraw-Hill for making this book possible—especially Simon Yates, who didn't complain when I told him about my vacation in Europe as the book was in the final stages. Robert Kern and his production team did excellent work pulling this book together in a short amount of time. |
|
||||
|
|
Rasmus Lerdorf deserves a note of thanks because he created PHP in the first place—and released it to the world. |
|
|
|
|
Jerry Libertelli, founder of G. Triad, introduced me to Brad Morton (who helped with the authentication chapter). While writing this book, Jerry and his team provided PHP and Linux support and service for my test environments and clients. |
|
|