Slashdot Mirror


PHP MySQL Website Programming

Alan Knowles writes "Ever started looking for a PHP script to solve that problem in your company - Managing the passwords, keeping track of equipment, or making information available on the web. Normally after a few hours of hunting, you track down something that looks close to what you want, you download it, get it going, then start digging around the code. At this point, you cringe in fear of two problems, the spaghetti mess that you are about to deploy, the ongoing maintenance nightmare and the horrors of modifying it to fit your needs. Well this book isn't going to solve these issues, but at least if a few more of those budding open source developers read it, the world would be a better place." Read on for the rest of this review; Yes, the book is still available. PHP MySQL Website Programming Problem - Design - Solution author Chris Lea, Mike Buzzard, Jessey White-Cinis, Dilip Thomas pages 504 publisher Apress rating 9 reviewer Alan Knowles ISBN 1861008279 summary Effective learning through the Problem, Design, Solution approach

In brief: This book takes you through designing a PHP website, featuring the usual bundle of generic features, simple content management, adverts, forums and an on-line shop. It's not intended as a definitive codebase of the absolute best design, but fills a big gap between trying to develop PHP with functions and lots of include files, and the full Computer Science bible of Design patterns.

For those people (and there's a lot of them) who have grown from Word macros and Visual Basic, then had a lot of fun learning PHP, this book provides an excellent gentle path towards using classes in PHP and applying them to real world problems. Like a lot of Wrox books, it's jam-packed with code, with a good flow of new information in each chapter.

What I liked

As a programmer who many years ago swore blind that there was no reason for using classes and objects on websites (the equivalent to a misspent youth), this book gives good clear examples on how they can provide advantages over just 'include' and a few functions.

The book is enjoyable to read; it focuses on the step-by-step delivery of a very dynamic website,starting with the basics of designing the file layout and how the files will work together. It then goes into more detail on delivering each feature, provides enough general ideas to help most PHP enthusiasts and budding developers understand the basics and advantages of OOP programming (although there are a few functions thrown in to ease in those not conversant with OOP).

The website that you learn to create (using the Problem - Design - Solution approach) is available for you to see online here.

Although a lot of the code is focused around implementing a reasonably simple set of Patterns, Data Objects and Page execution scripts, there are a few gems in there.

  • Utilizing quite a few PEAR classes including the Database abstraction layer, Mail Sending.
  • A nice section on the basics of RSS and XML, not to detailed level, but a good warmup for anyone coming from a System Admin or Simple Visual Basic level.

Ok, It's not for everyone. If you've done any Java or C++, this book is going to be a bit below you. Design Patterns are not mentioned directly in the book, although a number are implemented. The book misses out on quite a few important ideas, like templating php sessions in the body, although it does touch on the subject near the end. Given the target audience, of PHP of beginner to intermediate level, it does have a few unusual code styles in places, which hopefully the readers will not over-apply.

What you will learn from this book
  • Elements required to build a useful 3-tier web application
  • Design and construct an interactive User Interface (UI)
  • Provide a CMS environment to manage content securely and extensively
  • Create visitor accounts, to register and manage unique site visitors
  • Build a simple news management and delivery system
  • Create a syndication application
  • Generate a sustainable revenue stream from advertising
  • Implement an online visitor poll
  • Create a fully featured discussion forum
  • Build an online shopping cart system with checkout features
Summary While personally this isn't the book for me, as I've learned far too much PHP for my own good, it's the book you wish half the sourceforge PHP project coders would read before starting their project, saving you a wasted download. In the end it's ideally suited to a PHP website development training course, and could almost be the course book. (However, it's better written than most of the school books I remember).

You can purchase PHP MySQL Website Programming from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

34 of 160 comments (clear)

  1. Who needs this? by Anonymous Coward · · Score: 4, Funny

    Seriously, a college education in MIS provided everything you need to create a fully scalable, multifacted, fully functional e-commerce portal to create new paradigms of customer interaction.

    1. Re:Who needs this? by mgrennan · · Score: 2, Funny
      I've working in MIS for 25 years. I have a high school education and a brain.


      In this time I have worked for two PHD's in computer science and both thought I also had a PHD because they had to come to me to find out how things realy work.

      --
      There are 10 type of people in the world, those who understand binary and those who don't.
  2. Why WOULD you use classes and objects? by FyRE666 · · Score: 4, Interesting

    Although I use Java, where OOP is hard to avoid (and I wouldn't want to most of the time), I don't see the need to introduce the performance sapping abstraction of setting up classes and so forth with web scripts.

    Let's face it, by the time you've declared you classes, instanced everything a procedural approach would probably have executed and be wating for the next client...

    1. Re:Why WOULD you use classes and objects? by SweetAndSourJesus · · Score: 5, Insightful

      Portable code. It's nice to be able to reuse components.

      Ease of use. Once you've got your objects rolled up, just plug em in and go.

      Uhm, do I really have to explain the benefits of object oriented programming?

      The performance hit is something of an issue, but I think it's going to be resolved with the Zend 2.0 engine in PHP5.

      --

      --
      the strongest word is still the word "free"
    2. Re:Why WOULD you use classes and objects? by Lordrashmi · · Score: 2, Informative

      Using classes and objects makes a project alot easier to maintain. It is nice to know that every time data X is show on the page, it is provided by $someObject->getX()

      Unless each bit of data is always only shown once in a system, there is a place for classes and object.

    3. Re:Why WOULD you use classes and objects? by ebuck · · Score: 2, Interesting

      Well, I can see your point (as I once had it in the past myself) but to have that point you may be missing out on the techniques that (sometimes) favor the class based approach.

      You only pay for instantiation (setting up of classes) once, at the time of the class's creation. I have seen many projects fail to keep often used classes around, or worse, design a system that demands the recreation of often used duplicates.

      Most of the time this is due to fresh java talent leveraging their accumulated problem solving skills in ways that subtly or overtly casue maintainability or performance issues in Java.

      Other times it is for various other pressures on the code (ie. management doesn't care, but wants it out NOW!)

      My point is that there may be two markets of web code. That which is suitable for the quick demo, test, one-off, which doesn't need to scale or handle monstrous punishment, and that which is written from the outset with scalability, maintainability, etc... in mind. Rarely will a site fall completely into one of these endpoints of the spectrum, but you get the idea.

      Code for a quick knock-off requires a language with a quick return on investment. This is why there are still people using sh/csh/ksh for install scripts, admin routines, etc. Php is not as coarse as these primitive examples, but unless more books talk about scaling PHP and improving code maintainability, PHP will constantly be open to critisim common to nearly all forms of scripted code.

      Code on the other end of the spectrum lives in a different environment, and comparing the two is just about as difficult as comparing the wages of "the average worker" in two countries on opposite sides of the world.

    4. Re:Why WOULD you use classes and objects? by telbij · · Score: 2, Insightful

      Let's face it, by the time you've declared you classes, instanced everything a procedural approach would probably have executed and be wating for the next client...

      It's already going to be twenty times slower than a custom Apache module in C. Performance is not the hallmark of interpreted scripting languages, development costs are. So if you're looking as whether you use classes or procedural scripts, the deciding factor is not going to be whether it took .01 seconds or .02 seconds to generate the page.

      I don't see the need to introduce the performance sapping abstraction of setting up classes and so forth with web scripts.

      Well then you've never built a large Web site with any kind of engineered infrastructure. Sure you can bust out a quick script to mail a form or something trivial like that, but suppose you have 50 forms and you want to keep track of who they mail to in a database, and you have 500 pages for which you want to generate bread crumbs and dynamic menus, then you have 5 designs that you may want to update without changing 50 pages at a time. Well you either better have a REALLY good naming scheme for all your functions, or you could use objects to namespace your functions and provide some kind of method to the madness. You could argue that such systems should be built in a more industrial language, but there is a HUGE niche for rapidly developed web apps with enough engineering to actually be useful for several years. Not all (or even most) complex Web sites have the huge audiences that merit extreme optimization.

    5. Re:Why WOULD you use classes and objects? by ajs · · Score: 4, Informative
      You missed the point of using an OO design model entirely. In fact, if these are the reasons you're using OO methodologies (much less language tools), you should probably stop.
      You cite:
      • Portable code [...] reuse components -- Beyond the fact that the word "portable" is mis-used here, you're invoking the myth of OO reuse. Far better men (and women) than I have refuted this point, but I'll just summarize by saying that code reuse is not a feature of OO programming. It's a feature of modularity and quality of design. It's also very, very rare outside of library and toolkit design where it's always been, before and after the OO craze.
      • Once you've got your objects [...] plug em in -- That's called modularity. Not an OO feature, but a design feature.
      • Uhm, do I really have to explain the benefits of object oriented programming? -- No, they're well understood... er, or so I thought...
      So what are they?

      They're the building-blocks of OO, and the benefit is the flexibility that those building blocks give you. If you're a good programmer who writes procedural code, you'll usually find these features seeping into your programs anyway. Languages with OO features just make it easier to apply them. They are polymorphism (you know how to deal with a "car", so you don't have to read the manual to start up a "compact car"), inheritance (a "Pinto" is a "compact car" with some special differences like its own version of the "react to rear-impact" event) and encapsulation (a "car" has a "dashboard", a complex object with behaviors of its own). IMHO, polymorphism is the most powerful and valuable of these, though many will focus on inheritance, which is deeply tied to polymorphism anyway, so YMMV.
  3. Sounds familiar? :-) by tcr · · Score: 4, Funny

    Build a simple news management and delivery system

    Generate a sustainable revenue stream from advertising

    Implement an online visitor poll

    Create a fully featured discussion forum

    ?????

    Profit!!

    --


    Information wants to be beer.
  4. PHP Design by liveD+ehT · · Score: 5, Insightful
    I have been saying for years now that PHP design needs to be somewhat standardized so that we can all make our mods fit better. What I would like to eventually be able to do is have a framework opensource for a community/news-driven website that quickly figured out my needs, and my customer's needs, with security as a front-running concern. (ie: a way to really mix up the vars/dbvars and such so that it's harder to pry it open)

    The problem is that with security, the very best possible way to keep your site secure is to a) purify incoming data and b) keep your source to yourself unless you want people to let you know where the bugs/holes are. I know the open source community is really good and has it's place, but when it comes right down to it, if you fully customize your PHP, then it's more secure because there aren't a bunch of script kiddies looking for ways to hack you on security forums (a la PHPBB script attacks). The good thing about PHP in the open source sense is that you can read it and understand how it works. I don't recommend using any custom packages because there is risk involved that your doing so is going to attract attention from script kiddies. The best thing you could do is learn PHP by the open source examples (run phpbb and read it, run smarty and read it - understand it) but then create your own base, and add your own layers to it.

    1. Re:PHP Design by Mr+Bill · · Score: 5, Informative
      The problem is that with security, the very best possible way to keep your site secure is to a) purify incoming data and b) keep your source to yourself unless you want people to let you know where the bugs/holes are.

      The problem with this philosophy is that it allow you to be sloppy with your code. You might start out with great intentions of keeping the code clean, but without the fear of ridicule associated with peer review, you will start to slip to catch that deadline.

      Knowing other people are going to see the code is the best way to keep a programmer in line. An artist is not going to show all the crap they come up with to the world. They pick their best work and share it because they are proud of it.

      Now if only I could adhere to this philosophy myself...

    2. Re:PHP Design by telbij · · Score: 2, Interesting

      I have been saying for years now that PHP design needs to be somewhat standardized so that we can all make our mods fit better.

      Fit better with what? If you want a standard Web site, there's plenty of content management systems out there with a variety of module interfaces to choose from. If you want hard-core general purpose modules, look no further than PEAR.

      If you're suggesting there ought to be something between those 2 then go ahead and start a project, but I think there's plenty of open-source infrastructure out there already.

      If you're suggesting that there's a wide variety of PHP crap out there, then I agree wholeheartedly, but unfortunately there is no solution. The easier a language is to get into, the more beginners will release a bunch of crap for it. Your only option is to learn to sort through it.

  5. Hold it right there! by Anonymous Coward · · Score: 5, Funny

    "For those people (and there's a lot of them) who have grown from Word macros and Visual Basic, then had a lot of fun learning PHP"

    What do you mean, "fun learning PHP?" I'm a Microsoft guy and there's only one way for me... the Microsoft way. Buddy, I think you should be talking about ASP and VBScript, the nectar of the gods.

    I started my career hacking up Word macros, then slowly picked up Visual Basic. I can't wait to see what Microsoft has in store for me next. Maybe Visual C#? Hmmm... I won't touch anything non-Microsoft with a ten foot pole, because Microsoft always comes out with the best cool shit and I'm a big fan.

    I don't know why you people can't just accept Microsoft and all its products and move on with life.

    1. Re:Hold it right there! by alman · · Score: 2, Funny

      I agree.
      Microsoft pays my bills.
      And since I've pulled out all my hair, I don't have to worry about hair cuts, I get to spend that 1/2 hour/month reading MSDN magazine!
      Also, they helped provide me with this nice padded room, the walls are soft and squishy. Really nice.

  6. Two Problems? by Anonymous Coward · · Score: 5, Funny

    At this point, you cringe in fear of two problems, the spaghetti mess that you are about to deploy, the ongoing maintenance nightmare and the horrors of modifying it to fit your needs.

    There are three types of people in the world: those who can count, and those who can't.

    1. Re:Two Problems? by HerbieStone · · Score: 2, Funny
      There are three types of people in the world: those who can count, and those who can't.

      Ahhh, reminds me of the Monty Python sketch.

      Ximinez: Nobody expects the Spanish Inquisition. Our chief weapon is surprise ... surprise and fear ... fear and surprise ... our two weapons are fear and surprise ... and ruthless efficiency. Our three weapons are fear and surprise and ruthless efficiency and an almost fanatical devotion to the Pope ... Our four ... no ... amongst our weapons ... amongst our weaponry are such elements as fear, surprise .. I'll come in again. (exit and exeunt)
      Reg: I didn't expect a kind of Spanish Inquisition.
      Jarring chord. They burst in
      Ximinez: Nobody expects the Spanish Inquisition. Amongst our weaponry are such diverse elements as fear, surprise, ruthless efficiency, and an almost fanatical devotion to the Pope, and nice red uniforms --

  7. Classes? by symbolic · · Score: 4, Insightful


    As a programmer who many years ago swore blind that there was no reason for using classes and objects on website

    I put together a javascript/php-based web aministration tool for a web site, that without classes, would have been a nightmare. Classes aren't necessary in every case, but when the problem space reaches a certain level of complexity, NOT using them can be a very poor choice. But then, after one decides that classes would be appropriate, using them effectively is a whole different ball game.

  8. build great code like this by DrSkwid · · Score: 3, Funny

    /></td>

    in 24 hours

    --
    There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
  9. SAMS PHP and MySQL - Web Development? by zhrike · · Score: 2, Interesting

    How does this one compare to the SAMS book?

    I used this one to get going, and found it very useful. Does anyone know if the book reviewed here
    presents any significant benefits over the book I mentioned?

  10. See also... by gmuslera · · Score: 2, Informative

    ... Web Database Applications with PHP and MySQL, from O'Reilly. It not have the same focus as this book, but will give also a lot of useful concepts.

  11. Object Oriented Classes by DarkHelmet · · Score: 3, Informative
    I do use PHP classes in some of the code that I create. I do not use it for everything I do, but there are a couple things that I find where it makes my life easier.

    My biggest gripe about PHP in regards to classes is that you CANNOT create a deconstructor function in your classes. Their reasoning is that they cannot make it where you know which order the deconstructors will be called.

    Instead, the workaround is to create a function to handle the script ending using register_shutdown_function(). This is incredibly annoying, and for the most part I don't even use it. It just forces me to write a function called ClosePage or something to that effect.

    I like classes, and it's worth at least looking into using them on your pages (at least for code you'll be constantly reusing). For those of you who are concerned about speed in using classes, get PHPA.

    Hopefully PHP5 will fix some of the issues in using classes in this language. But until then, be hesitant.

    --
    /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
  12. buy it cheaper at amazon by gnurb · · Score: 2, Informative

    It's $34.99 at amazon with free shipping. ($39.99 at bn)

    There's also a $5 off $35 coupon floating around...

    --
    hooray! it's a sex wiki
  13. Don't bother by larry+bagina · · Score: 4, Interesting
    There are 4 authors, and I'm not sure there was even 1 editor. Like many multi-authored books, half the chapters are spent repeating information that will be reworded by the next author. Maybe they could get jobs as slshdot editors? :)

    The example code is contrived and ignores a lot of real world problems. Of course, if you're writing a shopping cart of your own, you won't learn anything new here. If you don't know php and want to add some dynamic content to your web pages, it's a good book, though.

    --
    Do you even lift?

    These aren't the 'roids you're looking for.

  14. Re:Sounds familiar? :-) by red_dragon · · Score: 3, Funny

    To those familiar with it, #5 obviously is:

    --
    In Soviet Russia, Jesus asks: "What Would You Do?"
  15. Not just a PHP problem by phorm · · Score: 4, Informative
    With understanding that this article is a reference to a PHP book (and the more books to educate the undereducated... the better), the problem with shite code samples extends far beyond PHP.

    Part of the reason it applies so readily to this language, however, is the conceived ease-of-use. A lot of newbie users swap to PHP, pick up some bad samples, combine with existing bad habits they never grow out of, and eventually consider themselves "knowledgable" just to to long-term use. However, experience in duration != experience in education (standardization, etc).

    To shift the blame from PHP, I've been working on attempting to integrate a 3rd-party web-based system (Perl-base) into my place of work. At first, I looked at the code and estimated that I could do it relatively easily. What I neglected to realize, is that while some of the coding was done reasonably well... this seems to be a multi-person project and other sections are nightmarishly and un-necessarily complex.

    We need an article on "signs that you're working with bad code." So far I've found...

    • Poor indentation
    • Low commentation (for godsakes, use # and throw in at least a few words every now and then
    • Really ambiguous variable names: $x1, $x2, $blah, $stuff
    • Odd information passing: As a delimited string...which is interpreted differently based on certain conditions (contents of string may vary)
    Maybe we need a "warning signs" section. Anyone got one?
  16. Open source doesn't need a book to be better by damm0 · · Score: 2, Insightful
    but at least if a few more of those budding open source developers read it, the world would be a better place

    I take exception to this. Open source flourishes at all levels; the inexperienced, the intermediate, and certainly at the expert level. In fact, it is the progression of people from distributing code to distributing useful code that makes open source what it is.

    The day you can't download garbage code is the day open source dies.

  17. Good and bad reasons for OO by einhverfr · · Score: 2, Interesting

    I tend to use a hybrid approach. There are many things that are fast and easy using proceedural programming, and I would think that probably 90% of the programming I do is proceedural. Many of my prjects are entirely proceedural, and the rest usually have their core written proceedurally.

    That being said-- there are several reasons why I might use classes and objects:

    1) Complex data types being moved around. I often use them like structs.

    2) Sometimes extremely complex and recursive data structures benefit from having functions attached to them. For exmaple if I am generating a PDF from a database query and I want this to be extremely extensible, there is no substitute for OO in its elegence.

    3) SOAP integration is FAR easier with OO programming. If your application needs SOAP, I suggest using OO for every SOAP-related object.

    4) Sometimes I use objects to hide ideosyncrecies from the program. Usually, the program is not aware that this is an object, however.

    Bad things about OO:
    1) For most tasks, OO is sort of like slicing a loaf of bread with a table saw. It is unnecessarily complicated and wasteful (performance hit).

    To recap, I find that OO is useful with complex data interactions, wrapping non-standard behavior (making PostgreSQL's record set appear forward-only for example), and for SOAP integration. But I wouldn't use it just because someone says its cool ;-)

    --

    LedgerSMB: Open source Accounting/ERP
  18. PHP frameworks by tetranz · · Score: 4, Informative

    There are several promising PHP frameworks in development.

    Ports of Struts
    PHP.MVC
    Phrame

    And ezPublish 3 which is primarily a CMS but can also be used as a general purpose framework.

    IMHO for one of these to really take off (like Struts) is what professional PHP development needs.

  19. MIS = all you need to build ecommerce site? NOT. by john+bigbootay · · Score: 2, Informative

    Yeah, I work with a bunch of people with college degrees in MIS. Hmmm, let's see, we've managed to build 3 f**ked commerce applications in 4 years. I think the key ingredients you're looking for is EXPERIENCE and HUMILITY.

  20. OOP is waaaay oversold by Tablizer · · Score: 2, Interesting

    Time for this longtime "OO troll" to step in here. While I think OOP might contribute minor improvements for components with simple, stable interfaces (a relatively thing), it is no magic bullet by any stretch. I have not seen the alleged "proof" in this book, but most other cases of "proof" I have seen had warped reasoning, especially about how things tend to change over time.

    The world's patterns of change tend not to be hierarchical nor polymorphic. These "taxonomies" are artificial structures introduced by OO authors, but there is usually no "tree cop" or "polymorphism cop" in the real world that assures that new changes fit the shape of these concepts. Change is more random in my observation than OO proponents assume. Marketers and bosses that ask for new features don't care about the shape of OO when they invent requests. OO books present an artificial view of change patterns, and students take it as gospel. We need more science and less doctrine. To build good, lasting software, one has to first become a student of change. The change patterns I have observed so far do not fit OO for the most part.

    OOP Criticism Website

  21. Repeat troll by skillet-thief · · Score: 3, Funny
    I think this guy has a Perl script that automatically posts the same troll each time a php related story comes up. This is at least the third time I've seen this exact same text. At least it is posted as AC this time, usually it is posted by egg_troll or something like that.

    The astonishing thing is that it continues to work!

    --

    Congratulations! Now we are the Evil Empire

  22. Shopping cart is a terrible example by MemeRot · · Score: 3, Informative

    Checked out the shopping cart feature first, since I've coded a ton of shopping carts.

    TERRIBLE!
    I type in 9999999 (ad infinitum) in the quantity field and hit update.

    My quantity is mysteriously changed to 147483647. I'm just guessing that's the limit of signed ints on that server. No error message was displayed. Since the size of the field that displays the quantity box is 3, all you see is '214'. An end user of an e-comm site doesn't care what's behind the scenes, they care that the inputs/outputs make sense. This doesn't. The reviewer talked about Design Patterns. Who cares? On the web the first rule you need to follow to have a reliable application is 'Validate user data'. Do that obsessively and you'll probably be ok even if your back end isn't too slick. Fail to do that and you are sunk, no matter how efficient your code is.

    Then just to be sure I wasn't being too harsh, I ordered -3 of another movie. Works fine. So you can order three of one movie, -3 of another, and get them for free. Sorry.... a shopping cart without data validation (tedious as it is) isn't a shopping cart.

    I hit continue and am told I need to have an account first. I sign up for one. First thing - I'm prompted for my login. Grrr... pet peeve - maintain this in the session please. Then I'm not redirected back to the cart. Oops... lost sale there. So I continue.... lovely, I'm informed that "Error_ Your shipping info is not valid." Man... insulting too. I hate apps that set a user up to fail.... and this does. I update my shipping address as prompted... and nothing happens, I don't go back to the flow of purchasing. Yikes, another lost sale. Even on the last step, my -19.99 order is accepted with no problems.

    I know the shopping cart is being offered as an example only.... but c'mon, it should be a workable example. I am looking to learn PHP, but think I'll look elsewhere.

  23. my php project by pdEo2x5o3bq · · Score: 2, Interesting

    I have a message board system Im currently developing in php. Let me know what you think, and/or if you have any suggestions. thanks. The URL: www.webula.net -Josh PS- support for this project is appreciated. Email me at josh at webula dot net

  24. Re:No, not really by Lordrashmi · · Score: 2, Interesting

    I should have clarified. I don't think OO is the silver bullet that solves all problems. However, atleast in the software I write, I tend to load one group of data into an object, then call $someObject->getX(). If I called getX() from an include file, it would not know what version of X to get. You could however use getX($id) to fetch the data.

    Bottom line, it all comes down to what works for you and how you learn to think. I was struggling with using OO at my new job (They encouraged OO but there was still plenty of procedural) when all of a sudden I had an epiphany (sp?). Now when I think of software (And sadly even real life things) I think of the as interconnected, self contained objects.

    This is a debate that will never be settled though and thats part of the fun of talking about it :-)