Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
PHP Books Media Programming Book Reviews

Build a Database Driven Site -- Quick 251

norburym (Mary Norbury-Glaser) writes "The third edition of Build Your Own Database Driven Website Using PHP & MySQL is written by Kevin Yank, Technical Business Director for sitepoint.com, a popular online resource for Web development. Updated for PHP 5 and MySQL 4 in this edition, Yank has put together an easy-to-follow, hands-on tutorial using the tools and techniques necessary to build a functional database-driven Web site. Many Web designers don't have deep knowledge and experience in data coding but want to get started serving up dynamic Web pages. This book gives designers and beginning coders a concise introduction to PHP and MySQL and quickly brings the reader to the page-creation stage." Read on for the rest of Norbury-Glaser's review.
Build Your Own Database Driven Website Using PHP & MySQL
author Kevin Yank
pages 359
publisher Sitepoint
rating 8
reviewer Mary Norbury-Glaser
ISBN 0975240218
summary Using PHP and MySQL to Build Your First Data Driven Website

Yank starts with the basics of MySQL and PHP installation on Windows, Linux and Mac OS X systems (he notes PHP 4.3 differences as well), and walks the reader through his first PHP script (no, not "Hello World!"). This first chapter is well written, with step-by-step instructions and shell script examples. It will help even a newbie feel comfortable with the process, and encourage him or her to move on to the rest of the book.

Chapter 2 focuses on relational databases and SQL queries. This chapter is not an in-depth study of RDBMs, but rather an extremely brief overview of the concepts involved in order to introduce the reader to command line interaction with MySQL. A simple database is begun that will be used in later chapters.

Basic syntax and commands of PHP are covered in Chapter 3 (statements, variables, operators). There are a lot of simple examples here that clearly demonstrate the elemental concepts of PHP. Yank uses forms, user interaction and control structures (if-else, while loop, for loop) to illustrate some easy methods of data access and user interaction with PHP.

Chapter 4 combines the two previous chapters' concepts into the beginnings of a working data-driven Web site. Yank shows the reader how to use PHP to connect to a sample MySQL joke database ("A man walks into a bar....Ouch."). He introduces sending SQL queries with PHP (mysql_query, delete, insert, update), handling SELECT result sets and inserting data into the sample ijdb (Internet Joke) database.

Chapter 5 is devoted to relational database design, and expands the one-to-one relationship to many-to-one, one-to-many and many-to-many relationships, this chapter teaches the reader how to join data spread between tables into one resultant set. This chapter is not meant to deal comprehensively with the complexities of relational database design. Indeed, the author gives an extremely brief nod to the inherent informality of his approach and references other resources for deeper study. Yank's intention here, as with the entire book, is to use relevant real-world examples to illustrate the simpler types of relationships a beginner will experiment with and how to deal with complex data and table issues with good design practice.

The next chapter presents content management and restricted-access database administration without relying on the command line (a few hints on protecting pages with appropriate access restrictions are in the introduction to this chapter but aren't dealt with in any depth until Chapter 12). Chapter 4's mention of forms is revisited here, and forms are used to manage, add, search for, edit and delete data.

At this point, the reader will have designed a database, organized the data into categories, created Web pages to display the data to site visitors, and prepared pages for administration of the data. The HTML is separate from the data, thereby relieving the Webmaster from the onerous and constant task of having to refresh pages with content. Here, in Chapter 7, the reader learns to format and submit content without resorting to hand-written HTML by using PHP functions (Yank covers the more standardized POSIX regular expressions, not PCRE). Code examples for string replacement, boldface and italic text, paragraphs, hyperlinks and splitting text into pages are included. The last bit of this chapter is dedicated to automatic content submission and has a nice design note about creating a visible column to the joke table where newly submitted jokes are handled as a No value, which allows review by a content manager before being posted.

This leads well into Chapter 8, "MySQL Administration (backing up, access control, checking and repairing data files)." Yank explains mysqldump and the use of update logs to create a practical backup-management scheme. He also covers using the myisamchk utility to check and repair MySQL data files. Basic MySQL access control using GRANT (creates new users, assigns passwords and adds user privileges) and REVOKE (the reverse of those functions) is included in this chapter as well, along with some tips and tricks to prevent access control problems.

Chapter 9 "gets back to the fun stuff" with Advanced SQL Queries (sorting and GROUPing SELECT results, setting LIMITs, LOCKing TABLES, aliases, LEFT JOINs and Limiting results with HAVING) giving the reader a well rounded sense of the versatility and scope of SQL in general and the SELECT command in particular.

Yank veers from textual data in Chapter 10, "Binary Data" (image files, encryption keys, programs for download) and shows the reader how to deal with working with files in PHP, handling uploaded files in PHP, storing and retrieving binary data in MySQL and learning when to use semi-dynamic pages to lighten the load on server performance in the process.

Chapter 11 deals with creating persistent variables, and offers an excellent description of cookies and sessions in PHP. I like Yank's figure "the life cycle of a cookie," which shows a graphical representation of a PHP-generated cookie. Yank rounds out the chapter with a simple shopping-cart example that consists of PHP scripts handling a product catalog and a checkout page (very real world).

The final chapter of the book is titled "Structured PHP Programming," and focuses on techniques for organizing code in order to simplify management (using include files, writing your own functions and streamlining code within Web pages). Yank gives a lot of sensible advice here, and his approach is not preachy. He brings up many important pitfalls that developers fall into: too much code, difficulty of finding what you need, understanding how it works. As this is a beginner's book, I would say that good design, good technique and good sense go a long way and should be stressed at the start of anyone's career in coding.

Build Your Own Database Driven Website Using PHP & MySQL, 3rd Edition runs only about 350 pages with a clean, easy-to-read page design, comfortable typography, lots of script boxes and screen shots. The appendices cover MySQL syntax, functions and column types and PHP functions for working with MySQL. Errata can be found at sitepoint's Web site, and I can't stress enough the value of checking these out before delving into any technical or instructional book: the frustration level goes way down if you know in advance that there's a typo, or a step missing!

This is a beginner's book with the essential tools and techniques that will get anyone started with serving up their first dynamic Web site. The tutorial approach of this book makes it easy for any reader to follow the step by step instructions. Yank manages to cover pretty much every topic necessary to provide the reader with a clean overview of the topic. It's a quick read and gives the reader encouragement and enough knowledge to move on to more complex volumes on the subject. This book provides a great first step for the beginner."

You can purchase Build Your Own Database Driven Website Using PHP & 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.

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

Build a Database Driven Site -- Quick

Comments Filter:
  • For the last time! (Score:2, Insightful)

    by Anonymous Coward on Wednesday February 02, 2005 @04:43PM (#11554615)
    A summary is NOT a review.
  • by MBraynard ( 653724 ) on Wednesday February 02, 2005 @04:49PM (#11554669) Journal
    BAsed on this summary/review, this sounds like a re-write of the already free help files for PHP and MySQL. Truth is, you probably don't even need the MySQL help file as the PHP documentation covers interaction with the database pretty well and pretty much every webhost out there is running phpMyAdmin for the database management.

    And really, if you don't already have an understanding of basic DB design (tables, fields, records, data types, etc.) are you really going to be designing such a site? If you didn't, there are plenty of free resources on the web to help you do that.

    Programming is primarily a self-starter job. You learn by doing, and by using free resources out there on the web. Why pay money for a book that regurgitates already free information for two pieces of free software.

  • Coding Standards? (Score:2, Insightful)

    by codesurfer ( 786910 ) on Wednesday February 02, 2005 @04:51PM (#11554698)
    I wish these books would include a section or two on properly coding web apps and sites. Often people who begin coding with weakly typed languages such as PHP (not a knock against it) do not become familiar with proper design and memory management.
  • by anamin ( 796023 ) on Wednesday February 02, 2005 @04:58PM (#11554745) Homepage
    Because it's nice to have all of that information put into a single reference. When I need to look up something at a later date I'd much prefer having a book that I can quickly find the info I need, rather than digging through google, or finding out the site I book marked is no longer in existance.
  • by winkydink ( 650484 ) * <sv.dude@gmail.com> on Wednesday February 02, 2005 @05:05PM (#11554827) Homepage Journal
    Programming is primarily a self-starter job. You learn by doing, and by using free resources out there on the web. Why pay money for a book that regurgitates already free information for two pieces of free software.

    Programming well, on the other hand....

  • Re:SQLlite (Score:2, Insightful)

    by odyrithm ( 461343 ) on Wednesday February 02, 2005 @05:07PM (#11554845)
    SQLite needs to connect to a db in the fs anyway, in much the same way as mysql, pgsql, mssql etc etc client needs a socket connection. Don't get me wrong SQLite owns your socks, but it's no easier to use than *the real* dbms's.
  • by lukewarmfusion ( 726141 ) on Wednesday February 02, 2005 @05:09PM (#11554865) Homepage Journal
    1. Buy a book about how to make database-driven websites.
    2. Find the sections that tell you how to get it working.
    3. Don't read any more about it.

    Two words: "SQL Injection."
  • Mind your steps... (Score:4, Insightful)

    by LuckyStarr ( 12445 ) on Wednesday February 02, 2005 @05:13PM (#11554907)
    1. Which language you use - be it Perl, php,
    whatever - is not important. Know the language you
    program in BEFORE you start the project! Almost
    all scripting languages have the database interfaces
    you need.

    2. Encapsulate recurring themes like database
    selects, inserts and so on. Knowing your language
    helps. Balance abstractness against usability.

    3. Use a (at least moderate flexible) template
    engine.

    Then youre (almost) done.

    In the last few years I used PHP and Perl. Both
    have their advantages and horrors. PHP is getting
    (even) better fast. Perl is quite nice if you know
    it good, which could take a little time.

    I only used MySQL and SQLite. MySQL with InnoDB is
    very reliable under heavy loads and huge datasets,
    but gets rather clumsy to back up and replicate.
    SQLite is blazingly fast, but I cannot say anything
    about reliability. I wont bet my crown-jewels on
    it (yet).

    Anyway. Good luck.
  • Better book idea (Score:4, Insightful)

    by JeffHunt ( 129508 ) on Wednesday February 02, 2005 @05:19PM (#11554942) Homepage
    "Build a Database Driven Site - With a Skilled Contractor Who Actually Knows What He's Doing"

    Just a thought... :)
  • by just someone ( 13587 ) on Wednesday February 02, 2005 @05:20PM (#11554955)
    And teach people how to abstract connection information in a separate page.

    A whole bunch of items are about to break beacuse people need to use mysqli. It would have been nicer if all these hacks used some db abstraction layer.

    And anyone who has had to update some pages a newbie built, will say please learn to abstract the connection information into a single page, not one connection per page.

    Ayeee.
  • by prostoalex ( 308614 ) * on Wednesday February 02, 2005 @05:21PM (#11554962) Homepage Journal
    Two things that come to mind is search and scalability. Can you conduct quick searches through the files, and will the system scale if you become as popular as Slashdot, with thousands of daily updates (in form of user comments).
  • Re:SQLlite (Score:3, Insightful)

    by arkanes ( 521690 ) <arkanes@NoSPam.gmail.com> on Wednesday February 02, 2005 @05:24PM (#11554993) Homepage
    Eh? No. "connecting" in SQLite is managed by passing it a filename. It's orders of magnitudes simpler than installing, configuring, and connecting to a client/server RDBMs.
  • Comment removed (Score:5, Insightful)

    by account_deleted ( 4530225 ) on Wednesday February 02, 2005 @05:49PM (#11555304)
    Comment removed based on user account deletion
  • by MatthewNewberg ( 519685 ) on Wednesday February 02, 2005 @06:05PM (#11555492) Homepage
    Find a web host online that has PHP, MySQL and will autointall scripts for you. One such good one is http://secure.lunarpages.com/tracking/cgi-bin/clic kthru.cgi?id=mnewbe2 [lunarpages.com] Purchase Webspace Login and click the Mambo installer button. Done - You Now have a PHP/ MYSQL Web Site Or you can just install Mambo yourself http://mamboserver.com/ [mamboserver.com] That is my suggestion for a QUICK way to do it.
  • by Anonymous Coward on Wednesday February 02, 2005 @06:06PM (#11555499)
    Know the language you
    program in BEFORE you start the project!

    Dunno about that, the only way I've ever been able to learn anything is by using it for an actual project. Seems to work out ok.

  • Update is in order (Score:5, Insightful)

    by WebCowboy ( 196209 ) on Wednesday February 02, 2005 @06:19PM (#11555613)
    This was a couple years ago so could be completely wrong now.

    No completely wrong, but mostly:

    * The current release of PgSQL runs natively on NT/2K/XP/2K3 Server as a service. The Cygwin emulation and related kludges are not an issue with either database now.

    * PgSQL has been quite optimised in recent years, while at the same time MySQL has become rather less lightweight than it used to be. The only way to get any measurable performance benefit from MySQL over PgSQL now is to forego the use of InnoDB tables in MySQL (and the transactional ACID-compliancy/rollback capability that comes with them). Even then, it is only fast at SELECTs--speed of INSERTs, UPDATEs and DELETEs was never MySQLs real strom point in any case.

    * As far as volume of hits and concurrent users go, PostgreSQL is far superior because it has a mature, stable MVCC (multi-version concurrency control) solution that almost completely eliminates table and record locking. If you have a site that does frequent and random insertion, deletion and modification transactions PgSQL wins.

    * MySQL was perhaps simpler in the past, but that was because it's capabilities were much more limited. It isn't hard to use today, but it isn't exeptionally easy anymore. Furthermore, PgSQL has a lot more tools to ease administration tasks than it used to. I am puzzled by comments that PgSQL us hard to use--I actually find it is easier to use than MS SQL Server 2000 now. The documentation has come a very long way and you can point-and-click your way around PgSQL with PgAdmin, WebMin, and various PHP web-based tools.

    * There are a lot of large-scale PgSQL implementations that rival or exceed Slashdot in scale. The entire .org domain relies on the PgSQL platform for example.

    Anyways, I hope I haven't offended MySQL fans--it is a fine product and has enjoyed a great deal of success and advancement with its association with SAP for example. For a typical blogger/slashdot-style site MySQL fits the bill nicely as it has the largest installed base, doesn't handle mission-critical data, and the vast majority of activity is read-only.

    If the data in the application is *important* and is write-heavy then you'll find that the case is different than above. For mission-critical web-based systems PostgreSQL tends to be be chosen over MySQL. For example, the SQL-Ledger accounting system uses PgSQL and NOT MySQL. However, MySQL has grown up some and has become a viable option here too--it's just that PgSQL has a more established image as being not the fastest but themost reliable with your data.

    Just remember that if you decide to pass on InnoDB to max out performance of your MySQL database you better make damn sure you have a reliable UPS and don't trip on the power cord or bump the emergency power disconnect switch or you'll have a crisis on your hands...
  • by jgarzik ( 11218 ) on Wednesday February 02, 2005 @07:01PM (#11556111) Homepage
    Unfortunately, the book review sounds like the book is missing information on one of my pet peeves:

    Fully dynamic websites will crush your server.

    Dynamic websites may be easy for beginners with this book, but introduce (a) a large amount of data or (b) a large amount of traffic (e.g. slashdot effect), and your server will fall over faster than a debutante in her first set of heels.

    I was on the team that helped set up cnn.com [cnn.com], back in the "early days" of the Web. And more recently, during the U.S. presidential debates, I convinced FactCheck.org [factcheck.org] that their server would stop falling over, if they just exported their article database as static HTML files, rather than being 100% dynamic. (that indeed fixed the problem)

    Dynamic content has its place, but too many newbies make the assumption that a fully dynamic website is a good idea. For content that does not change frequently, it is often more wise to use triggers to export the data as static HTML than to continually query and generate the same dynamic content over and over again. Database query caches help, but not a whole lot. Static HTML pages, and dynamic pages that provide the HTTP cache/expire/etag info are much more friendly to the web caching infrastructure in your browser and at your ISP.

  • by packman ( 156280 ) on Thursday February 03, 2005 @05:45AM (#11560330) Homepage
    I agree that from the moment you need transactions & stuff or a seriously complicated database, you need Postgres. I'm not a Mysql fan at all, I use the best tool for the worst job but for web applications I seriously doubt Postgres has any chances in the mass-market because:

    1) Mysql has a much smaller memory-print. Try giving a database 4 or 8mb or ram to work with in both Postgres and Mysql and compare the performance. Postgres loses BIG time, while mysql runs without a glitch. Postgres is nice if you have 1 server dedicated to 1 application. Mysql is so popular because for low-end sollutions, it uses very little resources, which is exactly what mass-hosting companies need. Why do you think you see so little web-hosting with Postgres support?

    2) 95% of the queries performed by websites are typicly SELECT's - which is Mysql's strongest point.

    3) Most websites are not mission-critical. If you lose data - too bad, that are some blog's you lost, or maybe some reactions... Big deal. Btw - postgres's recovery after a powerfailure isn't perfect, I know a company that is switching to Oracle after a small postgres disaster half a year ago... They lost a rather critical table with +- 7 million records, and daily thousands are added.. Backup was from the day before, but they lost a whole day of pritty important transactions (crash happened at 21u in the evening, backup started at 21u30). No system is perfect, but now they have someone to blame...

    4) Postgres's duplication can't tip mysql's. In postgres quick hacks are available, Mysql supports load balancing and mirroring over multiple servers by default, and it's far superior to anything Postgres has.

    5) Postgres should be optimized for 1 application. There is no generic optimal configuration, differences in performance between applications can be extreme depending on the configuration.

    Mysql has it's purposes, so does Postgres, but I don't think they are competitors actually. It all depends on what you really need. I have experience with both, and for web-purposes - Mysql please... I plan looking into SQLite, which I already use for embedded purposes, but don't know how that is going to react in a multithreaded environment like a webserver.

Those who can, do; those who can't, write. Those who can't write work for the Bell Labs Record.

Working...