O'Reilly logo

Learning PHP & MySQL, 2nd Edition by Jon A. Phillips, Michele E. Davis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Preface

PHP and MySQL are a powerful combination that makes it easy to create web applications. If you’ve been creating web pages but want to build more sophisticated sites that can grow and interact with users, PHP and MySQL let you get started easily and then build complex applications on those foundations.

Our goal is to help you learn the ins and outs of PHP and MySQL and to save you some of the “Why doesn’t that work?” moments that we’ve already been through. We’ll show you what to watch for and how to fix these issues without pulling out your hair.

Audience

This book is for people who want to know how to create dynamic web sites. That could include graphic designers who are already working in an IT or advertising firm creating static web sites, and who may need to move forward with coding database-driven web sites. It might also include people who already know, say, Flash development and HTML markup, but need to expand their repertoire of skills to databases and programming.

Assumptions This Book Makes

This book assumes you understand how web browsers work and have a basic understanding of HTML. Some understanding of JavaScript may be useful (for Chapter 16) but isn’t generally required.

You might also be overqualified. If you already know how to create pages using MySQL and PHP, then you’d probably be better off with a book that is more a reference than a learning book, such as Paul Hudson’s PHP in a Nutshell, or Russell Dyer’s MySQL in a Nutshell, both from O’Reilly.

Organization of This Book

This book starts out with an overview of how all of the pieces you’ll be working with fit together. Because there are multiple languages and technologies that interact to form dynamic web pages, it’s best to start with a solid understanding of how the pieces work together. The PHP that you’ll learn works as an integration package for dynamic web sites.

Next, we’ll walk through installing the core software packages on your local computer. This book focuses on PHP and MySQL, but making this work also usually requires the Apache web server. The PHP interpreter works with the web server when processing dynamic content. Finally, you’ll install the MySQL database. Installation is covered for PC, Mac, and Linux systems. You can also use a hosted Internet service provider (ISP) account to develop your pages, if you don’t want to install everything locally.

Since PHP plays an important role in pulling everything together, we next explain the basics of working with the PHP language. This includes language essentials such as data types, program flow logic, and variables. Functions, arrays, and forms each get their own chapter to fully explore them.

Because you may be new to databases in general, we ease into MySQL by first explaining concepts that apply to designing and using any relational database. Then we give specific examples of using MySQL to interact with your data. Once you can get data in and out of the database, you’ll need to work with PHP to integrate that data into your dynamic content.

Security and access control get their own chapters. While security may sound like a dull subject, it’s still a huge issue if you store any private information on your web page. We’ll guide you around several common security pitfalls.

We also touch on how XHTML, the next generation of HTML, works with PHP and your web sites.

Finally, we close with sample applications that demonstrate how the technologies work together to rapidly build workable, fast web sites. You’ll also be provided with web sites and forums to gain additional information on the topics covered in the book.

Supporting Books

Even if you feel you are ready for this book, you may want to explore some of the technologies in greater depth than is possible here. The following list offers some good places to start:

  • Run Your Own Web Server Using Linux & Apache, by Tony Steidler-Dennison (SitePoint).

  • PHP in a Nutshell, First Edition, by Paul Hudson (O’Reilly).

  • MySQL in a Nutshell, First Edition, by Russell Dyer (O’Reilly).

  • CSS Cookbook, Second Edition, by Christopher Schmitt (O’Reilly).

There are also several good online resources for dynamic web development, including http://onlamp.com, part of the O’Reilly Network. LAMP stands for Linux, Apache, MySQL, PHP. LAMP is the de facto standard for serving dynamic web pages.

Conventions Used in This Book

The following font conventions are used in this book:

Italic

Indicates pathnames, filenames, and program names; Internet addresses, such as domain names and URLs; and new items where they are defined.

Constant width

Indicates command lines; names and keywords in programs, including method names, variable names, and class names; HTML element tags; values; and database engines.

Constant width italic

Indicates text that should be replaced with user-supplied values.

Constant width bold

Indicates emphasis in program code lines and user input options that should be typed verbatim.

Tip

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you can use the code in this book in your programs and documentation. You do not need to contact O’Reilly for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Learning PHP and MySQL, Second Edition, by Michele E. Davis and Jon A. Phillips. Copyright 2007 Michele E. Davis and Jon A. Phillips, 978-0-596-51401-3.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact the publisher at .

How to Contact Us

We have tested and verified the information in this book to the best of our ability, but mistakes and oversights do occur. Please let us know about any errors you find, as well as your suggestions for future editions, by writing to:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/9780596514013

There is also a blog for this book located at:

http://www.krautgrrl.com/learningphp/

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:

http://www.oreilly.com

Safari® Books Online

When you see a Safari® Books Online icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

Acknowledgments

We are happy to have this newly improved and expanded Second Edition out for our audience. We’d like to thank our wonderful agent, Matt Wagner of Fresh Books, along with Simon St.Laurent at O’Reilly for getting this Second Edition rolling; without them, this book wouldn’t be in your hands.

Second, profuse thanks to our technical editors, especially Jereme Allen, Charlie Maguire, and Peter MacIntyre for their fantastic edits to our book. We’d also like to thank our local Minneapolis/St. Paul PHP community: http://www.tcphp.org, which sparked our interest in PHP and MySQL years ago. Lastly, thanks to Simon, Mimi, and Zack for being patient while their parents reworked a very important book.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required