Please create an account to participate in the Slashdot moderation system


Forgot your password?
Databases Books Media PHP Software Programming Book Reviews IT Technology

How to Do Everything with PHP and MySQL 354

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's free newsletter. You can purchase How to Do Everything with PHP and MySQL from Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

How to Do Everything with PHP and MySQL

Comments Filter:
  • by Anonymous Coward on Thursday June 30, 2005 @04:52PM (#12953563)
    This is finally the book that I need to write my php/mysql based operating system. Linux and Microsoft are dead!
  • by Anonymous Coward on Thursday June 30, 2005 @04:52PM (#12953567)
    Step 1: Use Emacs as your text editor.
  • by Uber Banker ( 655221 ) * on Thursday June 30, 2005 @04:53PM (#12953572)
    How different is what this book covers from what this [], this [], this [], or this []?
  • by grazzy ( 56382 ) <> on Thursday June 30, 2005 @04:53PM (#12953577) Homepage Journal
    Dont buy a book about PHP AND MySQL.

    Seriously, buy one for each one of them.
    Then, when you've bought those two, you can stack them under your laptop and type in: [] []

    Ready to go!
    • 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 []
      • Hell the php .chm is wonderful [] as well.

        When I started developing in php and mysql I went out and bought "Open Source Web Development with LAMP". It was recommended, and apparently was very helpful. After an hour, put it on the bookshelf and went to, and haven't looked back since. Anything that is in these books I can usually figure out myself with the help files, and anything I cannot figure out myself usually isn't in the book (though there is always a web site somewhere with example code that

      • I have it shortened even more using a Firefox keyword. The URL is [] 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. :)
    • and get the php book from the library.


      php won't require lots of reference, once you learn something, you won't need to look it up. but with mysql, you will want a reference.

      the other reason, once someone learns php, they will probably want to move on to another language. save the $50 from the php book and use it for a Java book.

      that is if people are like me and have limited money. get the most bang for the buck. there is no reason to have a book that you use once and then don't need. it is be

      • No, buy a SQL book (Score:5, Insightful)

        by DogDude ( 805747 ) on Thursday June 30, 2005 @05:14PM (#12953791)
        I can't stress strongly enough that people NOT buy a MySQL book. Buy a SQL book. Even better, buy a RDBMS book. We have enough people doing stupid things with data. We don't need any more. You might as well suggest that somebody buy a Windows 95 book.
        • by njcoder ( 657816 ) on Thursday June 30, 2005 @05:43PM (#12954030)
          " I can't stress strongly enough that people NOT buy a MySQL book. Buy a SQL book. Even better, buy a RDBMS book."

          If people start doing that.... I can't see people still using MySQL :)

    • Would you really do that to your eyes?

      It's true, PHP and MySQL both ahev great doccumentation. It's very complete, the examples are well laid out and commented but to learn a language from the on screen doccumentation?

      I like to be able to lie with a book in bed, in the garden, on the bus, all the places I don't really want to be with a laptop.

      When you're physically coding at the keyboard the online doccumentation is often the fastest way to look up a query, but you can really get a feel for something by

      • by eddy the lip ( 20794 ) on Thursday June 30, 2005 @06:06PM (#12954367)

        I'm big on books for learning and reference. I like to read, and I like to read on paper. I almost always prefer to grab something from my bookshelf and flip through the index than dig through a website. And I really want to emphasize that the PHP site is not, not, not a good way to learn the language. It's great when you want to find out why something doesn't work as documented (it's probably in the reader comments), but it is entirely useless as a way to learn how to effectively use the language.

        And that's ok - that's not it's intent. All of this "you don't need a book, just go to!" is really doing a disservice to those new to the language, or those that would like to actually learn good programming technique. Regarding the latter, the reader comments are generally abysmal and show the ignorance common in a (relatively) young community. For those just starting out, random access to > 3000 functions is not useful. At all.

        With that little rant out of the way, I'd love a recommendation for a PHP book similar to Thinking in Java, or Advanced Perl Programming. I've looked, but all I've found are Dick and Jane Learn PHP, or dead tree dumps of the documentation.

  • by RelliK ( 4466 ) on Thursday June 30, 2005 @04:54PM (#12953590)
    It's called "Why Not To Do Everything with PHP and MySQL". ;-)
    • by Anonymous Coward
      What's wrong with "How to Do Everything with PHP and Postgresql" ?
    • We should author that book.

      MySQL has garnered such popularity because it is EASY. It is unfortunate however that easy does not mean good. MySQL is the Geo Metro of database systems. It's easy to drive and anyone can finance the thing. It pays to note that LAMP is the ultimate driving force behind the movement.

      As a result of this ease and the lack of knowledge needed to make it operational, there are more scripts than one can count that you just drop into a LAMP installation and *bing*, instant website.

  • haha (Score:3, Funny)

    by macaulay805 ( 823467 ) on Thursday June 30, 2005 @04:54PM (#12953591) Homepage Journal
    The quote at the bottom of the Slashdot page says it all:

    He flung himself on his horse and rode madly off in all directions.
  • by vlad_petric ( 94134 ) on Thursday June 30, 2005 @04:58PM (#12953623) Homepage
    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).

  • Versions (Score:3, Interesting)

    by amembleton ( 411990 ) < minus bsd> on Thursday June 30, 2005 @04:59PM (#12953645) Homepage
    Which Version of PHP does this book apply to?
    Which Version of mySQL does this book apply to?

    Specifically, does it cover PHP5?
  • by jbellis ( 142590 ) <`moc.rednelbeganrac' `ta' `nahtanoj'> on Thursday June 30, 2005 @05:02PM (#12953673) Homepage
    will be either "wooo! php rocks!" or "php sucks, use a Real Man's language like java."

    Which is sad, because as much as PHP sucks [], J2EE solutions suck just as badly in different ways. (That's another article.)

    • ...MySQL! There are a few of us who hang around /. who know databases (a very few), and we've always got to chime in whenever MySQL is mentioned.

      Oh yeah...

      MySQL sucks. Not a real RDBMS. Very limited. Not ACID compliant. blah, blah, blah.
      • Re:You forgot... (Score:2, Informative)

        by a1cypher ( 619776 )
        The book I was just reading on mySQL said that the InnoDB table's were ACID compliant...
        • Re:You forgot... (Score:5, Informative)

          by nxtw ( 866177 ) on Thursday June 30, 2005 @06:21PM (#12954630)
          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.

          • Re:You forgot... (Score:5, Interesting)

            by Osty ( 16825 ) on Friday July 01, 2005 @01:23AM (#12957976)

            They aren't the default table type, though.

            Worse than that, if the table type isn't available and you try to use it, MySQL doesn't fail. It'll happily go on, ignoring that you asked for InnoDB tables with ACID compliance, and pretend that it's actually doing something when you ask it to open/commit/rollback a transaction. This is one of those "user friendly" features that really isn't, and MySQL has a bad habit of doing crap like this. If I want a table of a certain type, and that type isn't available, the DDL should cause a failure. It shouldn't succeed silently, choosing a different table type than what I asked for.

            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.

            Don't forget, implementing those features will make MySQL slow! Real programmers don't need them! Well, not until MySQL implements them, anyway (wait, I thought implementing them would make MySQL slow? They's gots some kind of magic that can keep MySQL fast after implementing features that'll make it slow? Well hot damn!).

            Features come and go, and I have no doubt that the MySQL developers will continue to advance MySQL until it can effectively mimic a real RDBMS. The lack of features is just an additional reason to complain about MySQL. The real reason why Those Who Know Better (tm) give them so much shit is the developers' attitudes, that they think they know so much more than development houses that have spent 20+ years researching and building real RDBMS engines (Oracle, IBM, and even Microsoft). If MySQL developers would've just said something along the lines of, "We understand the importance of foreign keys for proper referential integrity enforcement, but we have other priorities right now and want to make sure that when we do implement foreign keys that we do so in a robust and performant way," I wouldn't have ever had a problem with MySQL lacking foreign key support (just used as an example). Instead, they had an attitude like, "You don't need foreign keys. If we implemented them, they'd slow down MySQL, and besides, if you're a good enough developer you can compensate for the lack of foreign keys in your application code." That attitude earned them the scorn and distrust of anybody who knows anything about RDBMS design and usage.

    • will be either "wooo! php rocks!" or "php sucks, use a Real Man's language like java."

      Or "Ruby on Rails is 202% Better!!!111!"

      I don't know how to use RoR but all the trendy powerbooks people are using it so it's got to be cool.

    • Which is sad, because as much as PHP sucks, J2EE solutions suck just as badly in different ways. (That's another article.)

      This is wildly unfair to both technologies.

      PHP can suck in some ways. J2EE can suck in others.

      However, what critics of J2EE often forget is that J2EE can be used in a very light manner. Major applications have been written using only JSP pages, possibly using a rich set of tag libraries. This allows development of scripted pages in a very similar manner to PHP, but with the abilit
      • is only light relative to even heavier Java solutions. :-|

        Invariably people who sing the JSP praises have no significant experience with a real lightweight toolkit (Spyce, CherryPy, RoR, ...)

        But that's okay, because doing things the hard way builds testosterone.
  • by skoda ( 211470 ) on Thursday June 30, 2005 @05:07PM (#12953717) Homepage
    The combination of the two is rapidly emerging as a favorite, partly because they work well together

    Didn't PHP / MySQL emerge as a favorite about 5 years ago? Isn't the pair now a fully emerged favorite? Did I dream the year 2000 or has the author been Rip Van Winkling?
  • by Anonymous Coward
    The Visual Basic and Access of the next generation...
  • Make it stop (Score:5, Insightful)

    by glwtta ( 532858 ) on Thursday June 30, 2005 @05:09PM (#12953745) Homepage
    I wonder if there really isn't a single person out there who knows MySQL and PHP and who can write a decent book?

    Seems like the only explanation for this myriad of redundant books on such a simple topic. Really, how can there be a market that can accomodate another one of these identical books every month?

    • Beats me, but I would be satisfied with just one good PHP book that dealt with some more advanced topics. Something like "Design Patterns in PHP", or "How to Architect a PHP Web Application That Isn't 5 Thousand Unmaintainable Spaghetti Files."

      I've been doing web app development almost exclusively with PHP for the last four years. I pretty much hate the language, but there are a lot of solid, pragmatic reasons to use it. The funny thing is, almost all of the "PHP suxor!" posts that I see here would be eas

    • Re:Make it stop (Score:5, Insightful)

      by nxtw ( 866177 ) on Thursday June 30, 2005 @05:53PM (#12954136)
      I think most people that can write a decent book and that *should* be writing books are smart enough to use a better database than MySQL.
  • I hate the title (Score:4, Insightful)

    by ( 653730 ) on Thursday June 30, 2005 @05:11PM (#12953763)
    "How to Do Everything? with PHP and MySQL"?

    I hate how people abuses of PHP. PHP is nice when you really need what things like PHP/ASP/etc provide, but these days some people use it for everything. I hate it. Take a look at blogs - they're not really "dynamic content", they're just static content which changes very frequently, still everybody uses PHP to implement them.
    • by AuMatar ( 183847 ) on Thursday June 30, 2005 @05:51PM (#12954107)
      "static content which changes very frequently"

      Doesn't that make it dynamic?

      ANd why not use PHP to implement them? Instead of ftping the file tomy computer, adding my new text, then ftping it back, I can just use a PHP script to add it to a db, and a second script to write it out to the world. Much easier. As someone who did things the bad old way once upon a time, this is a huge time saver.
      • Re:I hate the title (Score:3, Informative)

        by nxtw ( 866177 )
        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

  • But can you build a /. from PHP and mySQL? A lot of books will show you the bits and pieces that make up a comprehensive website but usually don't show you how to put the whole thing together.
  • Melonfire (Score:4, Funny)

    by MikeMacK ( 788889 ) on Thursday June 30, 2005 @05:19PM (#12953847)

    The companion Web site for the book is hosted by Vaswani's software consulting firm, Melonfire.

    Do I really want to read a book by someone who works for a consulting firm named after the ignition of fruit?
  • ... then every problem tends to look like a nail.

    - Hubert
  • Brilliant! (Score:2, Insightful)

    by Soong ( 7225 )
    By posting a comment on this article, I can troll two products at once! I'm a PostegreSQL snob and a Java snob!

    Of course, this book is just indicative of one of the key features of the Open Source movement: the ability to take two bad software packages and combine them to form something truely horrific.

    (I wasn't using that Karma anyway.)
    • Re:Brilliant! (Score:5, Insightful)

      by deuterium ( 96874 ) on Thursday June 30, 2005 @06:07PM (#12954383)
      I'm working on a simulator that involves large amounts of data, and originally started work with MySQL. It's so popular that I assumed it was the easiest to use. Since our product is sold as a workstation, I quickly realized that each unit would cost us $200 for the MySQL server. A quick search uncovered PostGres, which has really turned out to be just as easy to use, is free, and even has a .NET interface and simple administrative utility. Pretty nice. I don't know if it's slower than MySQL, but it's plenty fast for me. You can even do transaction processing. It's strange that even though PostGres is so old, there are almost no books available for it (aside from the Douglas text), while MySQL has dozens.
  • by stlhawkeye ( 868951 ) on Thursday June 30, 2005 @05:33PM (#12953966) Homepage Journal
    I must be some kind of retard, I build my stuff with Perl and PostgreSQL.
  • by bogaboga ( 793279 ) on Thursday June 30, 2005 @05:33PM (#12953971)
    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 [], are not good enough. I want one I can get for free.

  • Great Book! (Score:5, Funny)

    by po_boy ( 69692 ) on Thursday June 30, 2005 @05:47PM (#12954053) Homepage
    I\'ve just read this book, and it\'s great! I\'m going to use PHP and MySQL for all of my web-based apps now!
  • by the_european ( 880429 ) on Thursday June 30, 2005 @05:53PM (#12954131)

    Look at the examples given in the companion web site. There is code like the following, which is highly vulnerable to SQL injection [] attacks:

    $title = $_POST['title'];
    $content = $_POST['content'];
    $contact = $_POST['contact'];

    // validate text input fields
    if (trim($_POST['title']) == '')
    $errorList[] = 'Invalid entry: Title';

    Validate? Just by removing trailing spaces? People trusting this book's advice will be very sorry soon.

    // and later in the script ...

    $query = "INSERT INTO news(title, content, contact, timestamp) VALUES('$title', '$content', '$contact', NOW())";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

    One more example:

    // generate and execute query
    $id = $_GET['id'];
    $query = "SELECT title, content, contact FROM news WHERE id = '$id'";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

    No validation at all! User input thrown into the database without any check!

    It's unbelievable that in 2005, after all the outrage and cry about SQL injection ther is still a new book proposing such horrible code!

"Call immediately. Time is running out. We both need to do something monstrous before we die." -- Message from Ralph Steadman to Hunter Thompson