PHP Diary | scriptschool.com | PHP Scripts | TD Scripts.com

TD Pic of Day PHP - Run your own picture of the day script from any site anywhere with this handy script


[back]go back 07/28/00 "PHP and mySQL reference books reviewed" go forward[next]

Books I've read on PHP and mySQL

A common question I am asked is: what books do you recommend purchasing? This unfortunately is a difficult question, since when I go to buy books I look for reference books, not necessarily how-to books. I am one of those types of programmers that likes to poke through the code functions myself and use reference books and websites as the foundation of learning. Usually the people asking me the question are people who are either brand new to programming or relatively new. Since I don't really think it would be fair for me to recommend books I don't own or have never read, I'll present you books I do own and that I have found useful. A person could buy the books below, read through my diary entries thus far, and visit some of the other php informational websites and be writing some very nice scripts within 30 days with minimul time devoted each day, or a couple days if they really hammered their studying.

Core Programming by Leon AtkinsonThe first book I bought was Core Programming by Leon Atkinson. I still use it today as a reference book. I never really read it cover to cover, as I don't read many programming books that way. Typically I use them as references for the code. Mr. Atkinson shows you examples for most functions and it has a pretty good reference in the back. Better books have come out since this one was published, but when it first came out it was one of the best if not the best book out there on PHP. The second edition of PHP programming is due out in August, so that will probably have some nice updates on the new PHP 4.0 features.

Professional PHP Programming by WROX teamThe only other PHP book I personally own and have read is PHP Programming by the Wrox team. It is 909 pages, so it certainly isn't short on information with some wonderful appendices. They give some very good real world examples like building a full featured email proggy, a job application uploader and more. I looked at other books when I bought this a couple months ago and this one seemed to be the most comprehensive, and since purchasing it, I have not been disappointed. Here's a few things below that I picked up just skimming through it that I've found pretty useful to go back through some of my code and make better.

Don't use count($x) inside loops

As the wrox team points out in their book using the count function inside a loop is not as efficient as assigning a variable outside the loop because the count function is invoked EVERY time through the iteration of the loop. For example let's say we have an array named books and there are 30 elements in that array. We should write the iteration like this:

$size = count($books);
for($index=0; $index < $size; $index++) {
    // do whatever in this loop
}

Error suppression

By putting the @ in front of a function an error can be supressed that would be printed by PHP. The common error the Wrox team points out is the division by zero that can occur. I usually make code which will compare the value of the code rather than suppress the error. Let's take the following example below:

$number = 0;
$average = 3 / $number;
print($average);

Line 3 above will result in a division by zero error. The error will not be shown if you put a @ in front of the third line like this:

@print($average);

I would probably write the code above like this, however:

$number = 0;
if ($number > 0) { $average = 3 / $number; }
print($average);

I guess rather than suppressing error message I'd rather write code that makes sure there is no possibility of an error, but the error suppression tip is useful.

Great reference book for mySQLThe final book I'd like to recommend you buy for your reference collection is mySQL & mSQL by O'Reilly. The O'Reilly books tend to be excellent resource books, although they do sometimes suffer in thorough explanation, so they can be confusing for people to learn at first with. I wouldn't recommend you buy this book if you are brand new to mySQL, but I would recommend it highly if you have a fundamental grasp of mySQL. Once you pick up the mySQL basics this book is almost indispensible for referencing the various SQL commands and syntax. For instance the SELECT query which is the most common SQL query, there are at least a dozen pages dedicated to referencing the different functions available for you and a little bit of code example. I wish each function had a piece of example code demonstrating it's use, but it does point you in the right direction.

Please vote on the usefulness of this diary entry so other people will know if it is worth their time to read :)

How useful was this diary entry? Avg Surfer Rating: 3.84 (83)

[back]go back 07/28/00 "PHP and mySQL reference books reviewed" go forward[next]

PHP Diary | scriptschool.com | PHP Scripts | TD Scripts.com

Copyright 2000 php-scripts.com Last Modified 07/27/00 11:00