Slashdot Mirror


How to Do Everything with PHP and MySQL

Michael J. Ross writes "When it comes to creating a dynamic Web site with data store capabilities, the site developer can choose from many technologies, including PHP and MySQL. The combination of the two is rapidly emerging as a favorite, partly because they work well together, and partly because they are both available under open-source licenses. As a result, technical book publishers are cranking out a growing number of high-priced tomes that try to cover all of the details of either technology, or both. But for the developer just getting started in either one, there is a new title that could prove more accessible: Vikram Vaswani's How to Do Everything with PHP and MySQL, published by McGraw-Hill/Osborne." Read on for the rest of Ross's review. How to Do Everything with PHP and MySQL author Vikram Vaswani pages 381 publisher McGraw-Hill/Osborne rating 7 reviewer Michael J. Ross ISBN 0072257954 summary A tutorial on PHP and MySQL, geared to the new developer.

The publisher has a page on their Web site devoted to the book; for some reason, it lists the book as containing 400 pages, but my copy has 381. The page also has links to a table of contents and a sample chapter, namely the first one. For those readers with very slow Internet access or unstable Adobe Acrobat plug-ins installed, be aware that the sample chapter -- and even the table of contents -- are offered only as PDFs, but the two links give no warning.

Most technical publishers, for every one of their books, wisely have links to the errata and sample code, right there on each book's Web page. This is the best approach, because when readers are having difficulty getting a book's examples to work correctly, they want to be able to quickly find and download the most up-to-date sample code, as well as check the errata page for any bugs in the printed code. Unfortunately, McGraw-Hill/Osborne has their links to those two types of information in an easily-overlooked part of a menubar, using small black text on a blue background. The links are near the upper left-hand corner, and outside the content section of the Web page, where the typical reader would be seeking fruitlessly for them.

The companion Web site for the book is hosted by Vaswani's software consulting firm, Melonfire. The site has the book's table of contents (in HTML), a link to chapter 1 in PDF, a profile of the author, three full-length case studies, a feedback form, and an extensive collection of links to PHP and MySQL reference material, discussion lists, articles, and tutorials. At the end of the Introduction in the book, the author invites the reader to use that companion site for connecting with other PHP users, and sharing their thoughts on PHP and MySQL development. The site itself has no such forum, so the author probably meant the discussion lists.

The companion site also has a link to download a Zip file containing all of the sample applications from the book -- from chapters 7, 12, and 16 -- comprising nine PHP scripts, an SQL file, and a data file. The code snippets themselves do not appear to be included in the download. This shouldn't pose a difficulty for the typical reader, since few of the code snippets are long. Besides, typing them in on one's computer can help to reinforce the language syntax that one is learning, as well as decent code formatting (valuable for newbies).

The book is organized into four parts.The first of these presents the basics of PHP and MySQL, including the history and features of both technologies, as well as how to install them on Unix and Windows systems, verify the integrity of the installations, and make some critical security and configuration changes, such as changing passwords. Parts II and III cover the basics of PHP and MySQL, respectively. The fourth and final part describes how to use the two together. To that end, every chapter contains snippets of code to illustrate the ideas being described. In addition, each section is wrapped up and illustrated with a sample application. For PHP, the author shows how to build a session-based shopping cart. For MySQL, he presents a simple order-tracking system. For using PHP and MySQL together, he shows a news-publishing system.

Despite its title, the book clearly does not tell the reader how to do everything with PHP and MySQL. As the author notes in the Introduction, the book is not designed to be a complete reference for either technology, but instead intended as a tutorial for Web developers who are interested in learning how to do server-side scripting in combination with a database management system. Vaswani states that he does not assume prior knowledge of programming or database fundamentals, and that these basic concepts will be taught by example, using tutorials and realistic examples. I suspect a reader not familiar with HTML, however, could be easily baffled by the book. On the other hand, most if not all developers reading a book on PHP or MySQL are likely to already know HTML well enough to understand the output of PHP-enhanced Web pages.

One strength that this book has over many similar ones is that the author explains up front how to install PHP and MySQL, rather than relegating these topics to an appendix, or skipping them entirely. This is critical, because many programmers will find that the most challenging aspects of getting started with PHP and MySQL, are simply getting them installed and working, along with a Web server, such as Apache -- and not coding the applications themselves.

Another welcome aspect of the book is the author's enthusiasm for the technologies -- although characterizing MySQL as "quite friendly" (page 150) is a stretch. Furthermore, his explanations are clear and concise. In addition, Vaswani makes no pretense that his book has all the answers; he frequently refers the reader to URLs in the online manuals of the products, for more details. In addition, he does a nice job of illustrating the advantages of normalized database tables, and later explaining how to format query output -- an important topic omitted in many similar books.

Yet, like all books, this one is not perfect. There are a number of errors or pitfalls in the book that could confuse the reader. They range from incomplete explanations of what a user will see when running particular commands, to the sort of errata one finds in all technical books. I found over two dozen in total (there may be more). In the interests of keeping this Slashdot version of the book review close to the recommended length, I won't list all of the problems here, but will instead refer the reader to a longer version of this book review, if they are interested in those details.

Aside from its many minor flaws, I recommend this title to any programmer who wants to learn the basics of PHP and MySQL. Even though the publisher could improve their production quality, choice of binding, and Web page, the author has done a good job of clearly presenting the major points. Future editions could incorporate fixes to the errors noted in the longer version of this review, as well as better explain to the neophyte how to test/debug the code snippets. Nonetheless, the intended reader would be well served by this particular book.

Michael J. Ross is a freelance writer, computer consultant, and the editor of PristinePlanet.com's free newsletter. You can purchase How to Do Everything with PHP and MySQL from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

22 of 354 comments (clear)

  1. Comparison to Other Books? by Uber+Banker · · Score: 4, Informative

    How different is what this book covers from what this, this, this, or this?

  2. One size doesn't fit everything by vlad_petric · · Score: 4, Informative
    PHP has two major shortcomings as far as high performance is concerned:

    1. No proper database connection pooling (and no, pconnect is not connection pooling).

    2. Can't really run Apache2 in its threaded mode because a lot of php libraries are not thread safe (although php itself is).

    Don't get me wrong, I *love* both php and mysql, but for highly-trafficked sites, jsp is definitely a better choice (from my own experience).

    --

    The Raven

    1. Re:One size doesn't fit everything by anthony_dipierro · · Score: 2, Informative

      No proper database connection pooling (and no, pconnect is not connection pooling).

      Huh? What is it, then?

      Can't really run Apache2 in its threaded mode because a lot of php libraries are not thread safe (although php itself is).

      Clearly only a problem if you're using those php libraries that aren't thread safe, and even then, the performance increase of threaded apache usually isn't worth the additional programming overhead of dealing with threads - and if you really need to squeeze every ounce out of your boxes that you can you're probably better off not using apache in the first place.

      Don't get me wrong, I *love* both php and mysql, but for highly-trafficked sites, jsp is definitely a better choice (from my own experience).

      I can't imagine a site which is so heavily trafficed that the cost of hardware saved by using jsp vs. php is worth the cost of programmers to program in it. And then, you're probably better off not using apache at all in those situations. Of course, maybe you can find some cheap jsp programmers, but in my experience php is a lot easier to code.

  3. Re:Like the old saying goes by Nos. · · Score: 2, Informative

    I would have moded insightful instead of funny. I'm a fan of php, and one of the reasons I like it so much, is their website. Its a very complete reference to the language, and the user comments included with each function are inavluable. In fact, one of the best things about the website is its ease of use. If I'm trying to remember exactly how a function works, its as easy as http://ca.php.net/function

  4. Re:MySQL good, PHP not so good by moonty · · Score: 2, Informative

    The problem with these PHP run forums was not that they were written in PHP, but with the forums themselves. Blaming the language for the problems is like blaming the English language for mangling George W. Bush's speech, while the fact is that the English language is merely what he is speaking. Granted, there were security issues with PHP that didn't help much, but it isn't entirely the fault of the language.

    Also, you must not have explored PHP much if you don't think any large applications exist.

  5. Really?! by Silicon+Knight · · Score: 1, Informative

    Despite its title, the book clearly does not tell the reader how to do everything with PHP and MySQL.

    Darn marketing double-speak, gets you every time!

    One strength that this book has over many similar ones is that the author explains up front how to install PHP and MySQL ... This is critical, because many programmers will find that the most challenging aspects of getting started with PHP and MySQL, are simply getting them installed and working

    /sigh/ Practically every beginner PHP/MySQL book I've looked at describes installation in some depth. Quite often too much depth for my taste.

  6. Re:Versions by puppetman · · Score: 2, Informative

    Good point - and MySQL 4.0, 4.1 (sub-selects) or 5.0 (in beta - stored procedures, triggers)

  7. Re:You forgot... by a1cypher · · Score: 2, Informative

    The book I was just reading on mySQL said that the InnoDB table's were ACID compliant...

  8. Re:both available under open-source licenses? by Al+Dimond · · Score: 2, Informative

    MySQL is dual-licensed; it is available for free download, and if you wish you may distribute it under the terms of the GPL. A commercial license can also be bought, and I think that includes things like support and possibly the ability to distribute under different terms. I don't remember exactly...

  9. Not entirely correct by Safety+Cap · · Score: 2, Informative
    You cannot distribute MySQL without a license, but you can use it to your little "I 'program' databases... but what's this primary key thingie I keep hearing about" self.

    That being said, it is a toy database, and as such, should not be used on serious projects (i.e., anything that uses normalized data schemas and requires data integrity).

    --
    Yeah, right.
  10. PHP editorfor Linux, anyone? by bogaboga · · Score: 2, Informative
    Disclaimer: This *might* be moded off-topic but I'll still ask:

    If anyone can point me to a good *free* PHP editor for Linux, I'd be very glad. The editors for Linux I find here http://www.php-editors.com/review/, are not good enough. I want one I can get for free.

    1. Re:PHP editorfor Linux, anyone? by Anthony · · Score: 2, Informative

      You've tries all the free ones? Including Eclipse? Perhaps you'd like to write a review yourself. I noticed my PHP editor of choice is not on the list. GNU Emacs. It naturally has a PHP-mode.

      --
      Slashdot: Where nerds gather to pool their ignorance
    2. Re:PHP editorfor Linux, anyone? by terrencefw · · Score: 4, Informative

      Not trolling... I code PHP for a living. I maintain a codebase of around 750,000 lines of complicated legacy code.

      I use vim, but make sure you set ctags up.

      --
      Like tinyurl, but one letter less! http://qurl.co.uk/
    3. Re:PHP editorfor Linux, anyone? by Anonymous Coward · · Score: 1, Informative
  11. Re:Like the old saying goes by Martin+Blank · · Score: 2, Informative

    I have it shortened even more using a Firefox keyword. The URL is http://www.php.net/%25s and the keyword assigned is php. When I need something, I just enter:

    php strings

    and it takes me right there, and with seven fewer keystrokes than you, making me more efficient. :)

    --
    You can never go home again... but I guess you can shop there.
  12. [OT] Re:PHP editorfor Linux, anyone? by gregmac · · Score: 3, Informative

    If anyone can point me to a good *free* PHP editor for Linux, I'd be very glad.

    Kate

    Has syntax highlighting (including recoginizing builtin functions), bracket matching, code folding, regex search and replace, blah blah.

    If you want one that does fancier stuff like show you class structures etc, then I dunno. Eclipse has a PHP plugin I heard - dunno how it works. One of my friends is huge into zend studio (non-free), but he works at a university (where they think nothing of spending a students tuititions worth on a computer - what do you mean our programmers don't need 23" apple cinema displays?)

    --
    Speak before you think
  13. Re:Is that Realistic? by Anthony · · Score: 2, Informative

    Yahoo employ Rasmus Lerdorf. He is the author of PHP. They use a lot of front end servers. See here for an architecture discussion.

    --
    Slashdot: Where nerds gather to pool their ignorance
  14. Re:I hate the title by nxtw · · Score: 2, Informative
    By *dynamic*, they mean content that is somehow generated every time the page is viewed. Examples would be Slashdot, forums, high-traffic news sites, etc.

    ANd why not use PHP to implement them?

    It's unnecessary, that's all. A text or HTML editor with FTP, SFTP, or WebDAV can do the job just as well. And for sites that actually get traffic, it's best to minimize the amount of database hits and processing required to display a page.
    Just because you *can* is not a reason why you *should*. (Now if only I'd think that way while driving...)

  15. Re:You forgot... by nxtw · · Score: 4, Informative
    They aren't the default table type, though.

    PostgreSQL, SQL Server, Oracle, and many other database systems (including commercial and open source) have been ACID compliant for quite some time. Not to mention the abundance of features that other database systems have, like stored procedures, triggers, views, subselects, etc. Many of those features have not yet made their way into MySQL and may not until 5.1; some have been recently added to production releases; others are still in "5.0" beta.

    Even then, data integrity and features have never been a primary concern of MySQL developers.
    Access manages to beat MySQL; MySQL completely chokes (for whatever reason) on joins that Access handles in seconds. SQL Server, PostgreSQL handle these queries fine.

  16. Re:No, buy a SQL book by DogDude · · Score: 2, Informative

    But MS SQL and DB2 don't deserve to be linked into the same category.

    I was actually giving Postgre the benefit of the doubt by lumping it in with SQL Server and DB2. I've never used it, but I've heard good things about it. I was planning on giving it a shot once a version of Toad came out that supports it.

    --
    I don't respond to AC's.
  17. Re:No, buy a SQL book by dingfelder · · Score: 2, Informative

    toad does more than oracle now

    their mysql admin tool rocks
    http://www.toadsoft.com/toadmysql/toad_mysql.htm

    they also have a sqlserver version now too
    http://www.toadsoft.com/toadsqlserver/toad_sqlserv er.htm

    If you use mysql, oracle or sqlserver you are missing out if you have not tried toad.

  18. Re:Risk of SQL injection by Santana · · Score: 2, Informative

    This can be useful for you.

    --
    The best way to predict the future is to invent it