Welcome to PHP5 and MySQL Bible!
Although we’re biased, we believe that the PHP Web-scripting language is the hands-down winner in its niche — by far the easiest and most flexible server-side tool for getting great Web sites up and running in a hurry. Although millions of Web programmers worldwide could be wrong, in this particular case, they’re not. MySQL is the most popular open-source database platform, and it is the first choice of many for creating database-backed PHP-driven Web sites As we write this, PHP5 is in its third beta version, and PHP has continued to grow in reach, adoption, and features since we wrote the first two versions of this book.
Although we’re biased, we believe that the PHP Web-scripting language is the hands-down winner in its niche — by far the easiest and most flexible server-side tool for getting great Web sites up and running in a hurry. Although millions of Web programmers worldwide could be wrong, in this particular case, they’re not. MySQL is the most popular open-source database platform, and it is the first choice of many for creating database-backed PHP-driven Web sites As we write this, PHP5 is in its third beta version, and PHP has continued to grow in reach, adoption, and features since we wrote the first two versions of this book.
Contents at a Glance:
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ixAcknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Part I: PHP: The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 1: Why PHP and MySQL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2: Server-Side Web Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Chapter 3: Getting Started with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Chapter 4: Adding PHP to HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Chapter 5: Syntax and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Chapter 6: Control and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Chapter 7: Passing Information between Pages . . . . . . . . . . . . . . . . . . . . . . . . . 119
Chapter 8: Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Chapter 9: Arrays and Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Chapter 10: Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Chapter 11: Basic PHP Gotchas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Part II: PHP and MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Chapter 12: Choosing a Database for PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Chapter 13: SQL Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Chapter 14: MySQL Database Administration . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Chapter 15: PHP/MySQL Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Chapter 16: Displaying Queries in Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Chapter 17: Building Forms from Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Chapter 18: PHP/MySQL Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Chapter 19: PHP/MySQL Gotchas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Part III: Advanced Features and Techniques . . . . . . . . . . . . . . . . . . 363
Chapter 20: Object-Oriented Programming with PHP . . . . . . . . . . . . . . . . . . . . . 365
Chapter 21: Advanced Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
Chapter 22: String and Regular Expression Functions . . . . . . . . . . . . . . . . . . . . . 421
Chapter 23: Filesystem and System Functions . . . . . . . . . . . . . . . . . . . . . . . . . 439
Chapter 24: Sessions, Cookies, and HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Chapter 25: Types and Type Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Chapter 26: Advanced Use of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
Chapter 27: Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
Chapter 28: PEAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
01 557467 FM.qxd 4/5/04 11:09 AM Page xvi
Chapter 29: Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
Chapter 30: Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
Chapter 31: Exceptions and Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
Chapter 32: Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
Chapter 33: Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
Part IV: Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
Chapter 34: PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
Chapter 35: Oracle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
Chapter 36: PEAR Database Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
Chapter 37: E-mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
Chapter 38: PHP and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
Chapter 39: PHP and Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
Chapter 40: PHP and XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
Chapter 41: Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757
Chapter 42: Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775
Part V: Case Studies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799
Chapter 43: Weblogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
Chapter 44: User Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819
Chapter 45: A User-Rating System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857
Chapter 46: A Trivia Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871
Chapter 47: Converting Static HTML Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913
Chapter 48: Data Visualization with Venn Diagrams . . . . . . . . . . . . . . . . . . . . . . 945
Appendix A: PHP for C Programmers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 967
Appendix B: PHP for Perl Hackers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973
Appendix C: PHP for HTML Coders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 979
Appendix D: PHP Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 987
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 997