Ninjas are deadly. Chipmunk Ninjas are just weird.
About this blog
Marc Travels
Marc on Twitter
JustLooking on Twitter

Marc Wandschneider is a professional software developer with well over fifteen years of industry experience (yes, he really is that old). He travels the globe working on interesting projects and gives talks at conferences and trade shows whenever possible.

My Publications:

My book, "Core Web Application Programming with PHP and MySQL" is now available everywhere, including

My "PHP and MySQL LiveLessons" DVD Series has just been published by Prentice-Hall, and can be purchased on Amazon, through Informit, or Safari

Feb 04, 2006 | 10:57:01
PHP Book Addenda I
By marcwan

As I sat down to edit “Core Web Application Programming with PHP and MySQL”, I would sometimes find errors in the text so blindingly obvious and stupid that I would question whether or not I was truly qualified to write such a book. And yet, after talking with some other people who write books (and recalling days when I wrote huge amounts of code), it seems that this is all common and with much proof-reading and the hard work of some friendly reviewers, I was able to write a book of extremely high quality.

Of course, that just meant I would be even more devastated when the first technical errors WERE found in the book.

There have been a couple, but they’re not that killer serious.

Chapter 21 Error

In Chapter 21, where the book discusses writing your own output handler, the constant in the $_SESSION array to check is HTTP_ACCEPT_ENCODING, without the letter ‘S’ on the word accept.

The Accompanying Source Code

There are a couple of errors in the source code, the most glaring of which DID get fixed, but never made it on to the shipping CD ROM (d’oh!). In the SimpleBlog sample, in the file lib/, the class DBManager is accidentally misspelled DBMananager. Just fix it and change it back to the correct spelling and the sample will compile fine under PHP 5.0.x (x <= 4).

The other problem with the samples is that some new things have appeared in newer versions of PHP 5.0.y (y >= 5). PHP now defines a class called InvalidArgumentException, which conflicts directly with the class I have defined using the same name. The easy fix for this problem is to simply change the name of the class slightly, to something like MyInvalidArgumentException or some such thing.

To save you the hassle of tracking down and fixing all of these problems, I have put a new copy of the book source code up on the servers. You can download these from here:

As always, if you see any other problems or errors in the book, or just want to comment on it, please feel free to drop me some mail.

I remain chagrined, but I’ll get over it.

Comments (56) Add Comment | Tags: php mysql web applications application book addenda errors
Incoherent drivel (rant)
Posted By: Charlie Stevenson Feb 04, 2006 14:34:54
Hah... yeah I'm sure it goes with the territory. I just downloaded your new zip and am about to check it out. I have this weird issue with exception handling where I get the blank screen of death. It's quite frustrating when the logs show that nothing funky happened and I get an empty page. Perhaps I goofed up when I was tinkering around on the simple blog code base. I've found that creating a Makefile that runs a recursive `php -l` is a good way to check for bugs before I actually reload in the browser. Are there any other tips? How does one gdb on php? Is there a way to step into the mod_php when the client loads a page and go through line by line? Another strange problem I have is with PEAR. I moved over to DB_DataObject + DB_DataObject_FormBuilder_Frontend or something long and nasty close to that... which is quite cool. I'm basically as a newbie able to hash out my database schema... load it into mysql and then dump it into PHP classes. So then I went through and replaced most of your code that grabs a connection with the PEAR code and such. Anyways, the problem arises as I think you mentioned somewhere that E_STRICT really bitches constantly about the fact that PEAR code is all using deprecated methodologies. So I've tried everything... error_reporting(E_ALL) is supposed to work. I also tried even going to the extent of changing the php.ini to something like E_ALL | ~E_STRICT or just plain E_ALL... I might have even tried E_NONE or whatever the keyword is. Nothing works. Sporadically when I load the page I get a nasty error about DB_DataObject calling var without public/private/protected or Unknown. And the only way to get around it is to click Write New Entry which takes me to the login page. Somehow at that point the error goes away for the length of that session. Probably all luser errors and growing pains.

Thanks for the book! Out of the 5 books I've purchased in a recent binge to muck with AJAX type sites yours is the one I pick up most frequently.

Small note
Posted By: Charlie Stevenson Feb 04, 2006 15:24:36
Me again... just started diffing the includes. I believe this small fix still applies to

< class NoEntrySpecified extends Exception

> class NoEntrySpecifiedException extends Exception

MySQL 5 ?
Posted By: Stephen Shaw Mar 11, 2006 04:35:44
Question. I see that you are providing MySQL 4.1 with the book. MySQL 5 is now out. Being new to PHP/MySQL I was wondering if there are compatability issues with the source in the book with MySQL 5?

Core Application Book
Posted By: suttungr Oct 16, 2006 15:34:54
I tried your Ecommerence code in your book but, received the error:
Parse error: syntax error, unexpected $end in /Library/WebServer/Documents/webapp/showprods.php on line 148

I can not get this program to work. It seems if you remove the echo <<<EOHTML... EOHTML code, the error is not there but you will not see the jpg files and html output.

What give?
Cannot redeclare DateTime class
Posted By: Parka Jan 27, 2007 01:17:39
Almost similar to the InvalidArgumentException problem is the DateTime class that was declared in the file.

After renaming it the class to MyDateTime, most of the problems went away.

I was using PHP Server version: 5.0.27-community
blank screen
Posted By: marcwan Mar 17, 2007 07:25:49
the blank screen is almost always the result of an error of some sort. i've noticed that enough has changed in PHP 5 since i wrote the book that there are random compile errors.

The best way to see what the errors are? Open up and temporarily comment out the set_exception_handler() and set_error_handler() function calls. Then you'll see the messages right away.

Blank Page
Posted By: marcwan Apr 01, 2007 19:40:19
The blank page usually means some really early on error is happening before we even get to PHP's error handling.

the easiest way to see what the error is is to open lib/ and comment out the two lines:

set default_exception_handler(....

then you'll see what the problem is.
A few tips
Posted By: marcwan Apr 21, 2007 23:42:16

I've found that PHP is a little quirky i how it reports errors for a lot of things. In particular, those that occur as it loads in scripts -- syntax and parsing errors.

Good things to look for:

- check your error settings in php.ini and make sure that it's reporting all errors (I usually set the errors to E_ALL | E_STRICT).
- also set the php.ini file to log errors to a log file. Sometimes, when you can't figure out what's going wrong, the error file will tell you what happened.
- once you've made sure that the set_error_handler and set_exception_handler are commented out, you should have a better time of seeing what's going wrong.

I'm planning on writing a blog article about this, as PHP appears to have two "modes" of error reporting, and getting the full details of all of them can be a bit tricky sometimes ....

Weird Characters
Posted By: marcwan May 19, 2007 00:37:13

Hey Scott!!

Those weird characters () I *think* are the UTF-8 headers. It sounds like the files on your machine have the UTF-8 headers, and the PHP interpreter doesn't like them.

If you're on Windows, you might try loading and resaving (as UTF-8) the files using Notepad.exe, or if you're on a Mac, then you should try using, and also use UTF-8. On Linux I'd use Emacs, but there might be something easier.

{$min, $max}
Posted By: marcwan May 30, 2007 01:46:51
Hey Nick!

Yah, a guy from England pointed this out a while back, and I ended up writing an article about it.

I don't know why this worked in the versions I was using when I wrote the book, but not now .... freaky!

weird charactesr
Posted By: marcwan Jun 17, 2007 03:12:53
see my above comment on weird characters. probaby UTF-8 headers. you can usually remove them with Notepad.exe or (or Emacs on Un*x).

Layout Question
Posted By: Jaqui Dec 16, 2007 00:54:06
In reading the book I noticed that you use tables for the page layouts instead of using the xhtml & css recommended divs. Why use the tables instead of divs?

This isn't the first book on php and mysql apps I have read, it is though much more comprehensive than any other work I have seen. Great Job.
Another Thank You
Posted By: Kim Briggs Dec 30, 2007 18:24:25
I am only a PHP hobbyist, but I have read a good amount of literature on the subject of web apps. I highly recommend this book for its clear and concise-yet-complete treatment of the subject.

Actually came here to find the source of an error on the accompanying disk... Thanks!
simplebog blank page with php 5.2.3
Posted By: Kim Briggs Dec 30, 2007 20:35:56
Here is one way to get rid of the "blank page" condition for simpleblog. Commenting out the custom error handlers that Marc mentioned in (lines 128-9), I got an error message concerning a session error:

Fatal error: Uncaught exception 'SessionCompromisedException' with message 'We're sorry, but there is a good chance that your connection to this site has been compromised. Please ensure that you have applied the latest security fixes to your web browser, clear your browser cache entirely, and try again.' in .../inc/simpleblog/ Stack trace: #0 .../inc/simpleblog/ require_once() #1 .../public_html/simpleblog/index.php(21): require_once('/home/utree/pub...') #2 {main} thrown in .../inc/simpleblog/ on line 87

Commenting out the last session data test in (~lines 78-88) allows me to see the page. HTH.
User-Agent Changes
Posted By: marcwan Mar 29, 2008 01:52:38
That's a good point, and not a bad suggestion. Firefox seems to upgrade itself on my systems about once every month or so, which might freak users out a lot ... I'll look at changing that code.


Page is not redirecting
Posted By: Nathan Jun 01, 2008 20:00:33
I'm seeing following error. I have php-5.2.x and it is not working. I see that someone else has had this error. Is there a fix? It happens when I go from the index/home page on the Appointment Manager to any page on the top tool bar. This only happens the first time the page is accessed. I then go back to the home page and everything works.

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

* This problem can sometimes be caused by disabling or refusing to accept

Can someone help me on this one?
Access Denied
Posted By: marcwan Jun 12, 2008 04:23:15
that means your application is either using the wrong name or password, or the given user has not been granted permissions in the database.

you can select * FROM mysql.user to see who has permissions from which host, and you should double check that your app uses the right name / password combo.

Ecommerce Site
Posted By: Maureen Moore Mar 18, 2009 17:13:53
I downloaded the corrected version of the ecommerce application and re-installed everything but I can't use any of the code because it doesn't fulfill the most primary function of printing out the right total. When the user goes to checkout with his shopping cart, only the last item he ordered is added to shipping to make the grand total. What can I do with a shopping cart that displays the wrong total. This example is useless for me because it can't even add the total right.
Stale Connections
Posted By: marcwan Aug 27, 2009 03:33:05
The sample code in the book makes a new connection to the database every single time you make a new request to the web server, so there should be no "stale" connections.

You should never, ever use the $s_conn variable directly, but instead always use the getConnection() method. This should avoid problems like this.

good luck!
Add a Comment





Copyright © 2005-2008 Marc Wandschneider All Rights Reserved.