Where to start for the PHP noob

On the Habari development mailing list, Daniel Smith writes:

I am interested in learning PHP (object)/MYSQL programming in general, and Habari-specific in particular. As a php newbie, could anyone please point me to any resources, latest quality books, tutorials or whatever, that could help me to learn how this all works?

An excellent question, and something that we experienced PHP folks would all do well to answer to help bring more people in and teach better coding practices.

For beginning PHP and MySQL, I really like the Visual Quickstart series of books. They have clear chapter goals and are rife with examples. Combine the books on PHP, MySQL, and PHP and MySQL with a willingness to frequently search the online documentation for both tools, and you can accomplish pretty much anything you set yourself to. Obviously, these are not for seasoned code veterans, but I think they're just right for people just starting who don't want to be babied but instead want to learn real code.

One thing that I've always found useful is picking a specific project goal, the simplicity of which would be determined by how green I am on the topic, and trying to code it myself. Sometimes working through other people's code can be daunting.

That said, looking through other people's code to see how they do things is essential to being literate with the common conventions for coding. A good example of something that the PHP coding world does that you don't usually learn in a book would relate to database access.

When looking through the books on PHP, you'll see a lot of reference to commands for accessing MySQL. No project I know worth anything uses PHP's mysql commands directly. Instead, they use an abstraction layer that handles many of the mundane details of database use without having to write the same three lines of database connection code repeatedly.

The lesson from the above is to see what projects like Habari do for database access. Habari is very object-oriented code. Practically everything in Habari takes place in classes and objects. If this is not your mental paradigm, then it may take some relearning to become comfortable in that milieu.

On the plus side, you will be significantly rewarded for your patience in learning Habari's style of coding with code that is cleaner and more flexible than that of many other projects. And if you're starting out with object-oriented thoughts, then you'll be a step ahead of others who learned procedural coding and have bullishly stuck to it.

Perhaps the best resource Habari has to offer for teaching new coders is the IRC channel, where Habari developers occasionally roost. There, you can ask PHP questions and get real answers from people who often know what they're doing. The plus side of using #habari and not #php is that while many of us are seasoned developers, we have a commitment (at least I do) to making new people feel comfortable in our community. As we say, "community first."

I'm glad you've decided to take the plunge in learning PHP, and hope that Habari can offer you tools toward your success.


10 Responses to Where to start for the PHP noob

  1. miklb from bloggingmeta.com 2007-11-13 22:38:44

    I appreciate the book recommendations, I've never had anyone specifically recommend a particular book, nor the suggestion of picking a project goal, and going at it from scratch, vs trying to pick apart someone else's. Seems obvious now that I read it. Any suggestions for a starter project, specifically if one were to want to go about doing it from an OOP standpoint? Better yet, a two parter, where the first part is strictly PHP, and once it's working, fold in some MySQL connections?

    And for other readers, I can attest to the openness of the seasoned PHP programmers involved in Habari with their knowledge, not to mention patient. It really is part of what makes Habari a great project to be involved with.

  2. Phill from quiproquo.wordpress.com 2007-11-14 04:13:47

    I second PHP and MySQL by Larry Ullman, that and the PHP website itself. The command reference is a fantastic resource, just append the name of the command you need help with to php.net/ and it'll tell you everything you need to know, including code snippets now and then.

  3. Chris J. Davis from www.chrisjdavis.org 2007-11-14 08:20:31

    Very well written post Owen. I think this answers the question quite nicely. And if you endorse something, people need to listen. You are one helluva coder.

  4. owen from asymptomatic.net 2007-11-14 09:24:43

    It's difficult to give an example project to try out as your first coding experiment, but I think that explaining why it's difficult may help you choose.

    First, you want to pick something that you are interested in. If I gave you something to try, your first inclination would likely be, "That doesn't sound too interesting." If it doesn't motivate you, it's not a good idea. Virtually every personal project I've ever done has been something that motivated me, not something I coded only because I wanted to learn.

    Second, be realistic. You know you're not going to write the next great YouTube/Facebook/Google on your first outing, so set your sights on something practical. Maybe code something you always wished your site could do.

    Third, keep in mind that a solo project doesn't mean that it's exclusive to the software that's already there. A lot of great applications are built using the API of existing software. Often you can become more knowledgeable as a coder by learning how to interact with software or a service that others don't. Look at the swelling market of people who provide WordPress templates -- it's just interfacing into something that requires specific knowledge. That's just an example of how knowledge of something specific can be valuable, not saying that creating templates is a real coding project for the purposes of this discussion.

    Fourth, like anything you ever design, think of the end goal before you start. Sure, it's likely to change as you code, such is the nature of being a client. The point here is that I'm not advocating the idea of "...where the first part is strictly PHP, and once it's working, fold in some MySQL connections." It would be better to plan to connect the MySQL connections from the beginning if that's the goal of the application. Sure, you could code it interface-first and then database, but thinking on how I write projects, my intuition says to do it the other way around.

  5. John 2007-11-14 11:17:24

    Hey, I just found your site when i was trying to remove that annoying restart box. I don't know if your still looking for books and such but I would also like to recommend w3schools.com as a resource. It helped me get off the ground with the basics. I'm not sure how many other languages you know but you should look into class structure once you get your roots down in php. Classes make dynamic websites so much easier to code.

  6. miklb from bloggingmeta.com 2007-11-14 11:47:08

    Fair enough, I was thinking more from an academic standpoint. But I can relate to the "not interesting" thought. Even in my limited skill sets, I recently skipped working on something I had started, as I wasn't "into" it at the moment,a nd chose another idea, and while doing it, learned a few things.

    Perhaps walking through the book would be the academic part I'm looking for, and would give me the base to make the decision of what I want to tackle on my own.

    Again, thanks for all of the help.

  7. Daniel Smith from opened.to 2007-11-14 17:20:06

    Thanks for the replies, all.
    I really appreciate it.
    Now, let the work begin!
    :)

  8. owen from asymptomatic.net 2007-11-14 17:29:02

    John, I'm glad that you were able to get going, but one of the resources I would not recommend is w3schools.com. Their information is poorly organized, usually lacks links to more appropriate reference sources, and is riddled with advertising. This is not the kind of environment that you would want to learn code from, and certainly not the greatest reference tool available.

    I had a college professor recommend this site during a summer "Intro to Web Sites" class for the purpose of teaching XHTML, which was fine for the level of class it was. It simply isn't as good a reference as a good book and the official documentation.

  9. stchatterbox 2007-11-14 21:28:59

    Owen, Thanks for your recommendation. I'll try to get a copy of the books you mentioned above. What's more, I'm interested to try out your Habari for my next website :)

  10. miklb from bloggingmeta.com 2007-11-22 22:37:52

    Just want to thank you again for the book recommendations. The PHP and MySQL for Dynamic Web Sites is exactly the type of thing I've been looking for, I'm just finishing up the second chapter, and I can honestly say I have a much better understanding of the stuff I've been mucking about in all this time. The small little example scripts give working examples of the different elements, which really helps put the elements into context. I can't wait to really start pulling it all together.

2673