Wednesday, September 9, 2009

Learning PHP, MySQL, and JavaScript: A Step-by-Step Guide to Creating Dynamic Websites

Author: Robin Nixon
Format: Paperback, 526 pages
Publisher: O'Reilly Media, Inc.; 1st edition (July 22, 2009)
ISBN-10: 0596157134
ISBN-13: 978-0596157135

Unless you've been hiding in a cave for the past ten years or so, you know that it takes more than a bit of HTML slight-of-hand to make a modern, dynamic website. The (so-called) Web 2.0 is constructed of a mix of technologies, creatively applied to allow the interactivity we have become accustomed to when surfing the web. Just looking at the front and back covers of Robin Nixon's book, he (and O'Reilly) promises to teach the reader all of the technologies (though I see no mention of CSS) required to bring your Web 2.0 creation to life, and send it out on the Internet. The best bit of news is that, according to the back cover blurb, "No previous programming experience is required." Really? We'll see.

Frankly, programming isn't all that easy. If you've never programmed before, you learn your first programming language and all of the principles of programming in general, all at the same time. This can be an enormous chore, compared to knowing basic programming skills and adding another language to your bag of tricks. Certainly learning PHP, JavaScript, and MySQL seems a daunting task for the coding newbie. There are entire books written on each of these technologies, just for the beginner. It seems that Nixon has quite a job cut out for him.

I checked, and the Preface does say in the Audience section, that this book is suitable, not only for webmasters and graphic designers, but also for high school and college students, graduates, and the "self-taught" (the latter would be me, so I guess this is a good fit). The next section does announce the Assumptions This Book Makes, so it's not all gravy. HTML is the only concrete assumption (and again, I'm surprised no mention of CSS is included, since it is largely required for web page formatting). While prior exposure to PHP, MySQL, and JavaScript isn't required per se, such exposure will allow the reader to progress through the book at a faster pace. That makes sense, but I'll hold the author and publisher accountable to their stated intent, that I (or anyone) won't need such exposure to benefit from this book.

One thing I liked (and I'm still not out of the Preface), is that the book references other books the reader should move on to, once they've completed Nixon's work. Dynamic HTML: The Definitive Reference (also by O'Reilly) is included which is another surprise, since the reader is assumed to at least be familiar with basic HTML, if not a "master" in this area. The other books are all O'Reilly publications (what else?), targeting PHP, MySQL, and JavaScript. No surprises here.

The first chapter is all high level concept regarding the nature of HTTP, and the various technologies headlining the book. Apache in specific, and open source in general also are included. Nixon seems to be setting the stage here for further learning to take place. The chapter is short, and ends modestly with a few simple questions for chapter review. The answers to these, and all the questions posed in subsequent chapters, can be found in Appendix A. This is a "good/bad" thing. It's good in that, if the reader gets stuck, he or she can pop back to the appendix, or just check to see if the answers they gave are correct. It's a "bad" thing in that, sometimes people get stuck quickly and, rather than trying to figure out the solution, will cut to the chase and head for the answer section. Generating effort to find an answer is how most people, especially me, learn. That said, it's better to provide confirmation, rather than have the student never know for sure.

To set up a website, you need a server. In this case, the server needs to be capable of providing basic web services, database services, and PHP. Enter LAMP (or WAMP if you're a Windows person). Setting up a basic LAMP (Linux, Apache, MySQL, PHP) or XAMPP server is ridiculously easy, as the site illustrates. The book uses other resources, such as, if you need to set up WAMP on Windows. MAMP is also available for Mac OS X people, so no one is left out of the loop based on OS of choice. So far, there's a significant amount of hand holding going on. What happens when the reader has to get their hands dirty with an actual programming language, such as PHP?

Hello world. Yes, this time-honored method of beginning to teach a programming language is introduced on page 34. The book's companion website hosts all the sample code used in the book. Just go to and then click on "Examples" to download the zip file. The site's table of contents also lets you select a chapter and section, to view sample code, if you don't want to refer to the downloaded files. Nixon faces the challenge of teaching both basic programming skills and PHP reasonably well. A programmer at my "day job" recently created the analogy of an array being like a series of shoe boxes. Page 40 compares arrays to a series of matchboxes, which is more or less the same thing. I mention this to draw out the teaching style used here. Learning a language is one thing, but you won't learn it well unless you understand why things work as they do. Besides, the goal isn't just to learn programming, but to learn it in the service of creating a "dynamic website".

There are five chapters that immerse the reader in PHP, before switching gears and moving to MySQL. Again, LAMP/WAMP/MAMP/XAMPP provides a handy "safety net" for the reader in managing everything and keeping it all in one container, but there's still a lot to learn. The last PHP chapter is a nice set up for the introductory MySQL chapter. Just when you think you're making some progress with PHP, you're sent back to "kindergarten" and the basics of relational databases (and as an aside, if the idea of databases is just too intimidating for you, check out The Manga Guide to Databases, which I also reviewed).

The next MySQL chapter puts what you've learned about PHP together with MySQL, so don't think you can forget chapters 3 through 7 at this point. It's not a straight shot from MySQL to JavaScript, which actually makes sense. Topics such as creating forms. and PHP templates are launched at you before you even breathe the word "JavaScript". After successfully (hopefully) tackling PHP, JavaScript becomes the second programming language the reader learns. PHP is a server-side language, and JavaScript works on the client-side, but the basic principles learned in the first, will handily serve the reader in learning the second. Variables and Arrays are still Variables and Arrays conceptually. The difference then becomes one of how each is expressed and managed in different languages.

JavaScript and PHP collide in Chapter 17 and Ajax enters one chapter later. Chapter 20 declares, "Bringing It All Together", but while reading this review may not have taken you much time, getting to this point in Nixon's book could take weeks or even months. This all depends on your dedication, available time, and how quickly you've managed to learn everything in the previous chapters. There will probably be some readers who become discouraged long before this point in the book, which is why regular use and persistence is required here.

Assuming you make it all the way through, and actually learn everything that's being taught, you'll be able to put together a relatively modest, interactive website, just using this book. No, you're not an expert, but you should be feeling a sense of accomplishment by now. The "Robin's Nest" website example used looks pretty vanilla flavored. I guess you'll still need to go out and pick up CSS to add some spice.

In addition to the end of chapter questions being answered in Appendix A, Appendix B lists various online resources to consult, but that's's just a set of lists of URL, but fun to explore. Appendix C and D cover MySQL FULLTEXT Stopwords and MySQL Functions respectively. My guess is that, you'll probably have started consulting external resources on dynamic website construction long before you finished this book which again, makes sense, though the book is quite self contained.

O'Reilly books tend to cater to readers who are already at least somewhat experienced, so it was nice to read and review a book that truly caters to the beginner. I would have preferred more end-of-chapter material, to test the reader's newly acquired skill sets, and I definitely would have included CSS as an assumed technology. It's not necessary for Nixon to teach CSS in any form, but style sheets are just too tightly integrated into, not only web site formatting, but in many cases, functionality, to just be ignored. That said, Learning PHP, MySQL, and JavaScript is a worthy effort on both Nixon's and O'Reilly's part, to introduce the programming and database neophyte into the world of dynamic website design.