07 Jun

book review: Learning PHP Data Objects

Overview: Learning PHP Data Objects, by Dennis Popel, is an introduction to PDO, which walks through the building of a believable test example – a library manager for your home library. Each chapter introduces a new facet of PDO and shows how to rewrite the appropriate parts of the application to slot the new ideas in. Very clear and easy to read. Non-PDO subjects are appropriately kept to the appendices.

I really couldn’t find very much about this book that I didn’t like. Ignoring the appendices, the book is 154 pages purely devoted to teaching PDO through examples, including error handling, working with BLOBs, even the creation of the M in MVC (Models).

I mentioned MVC there. One of my gripes with most tutorials of MVC is that they introduce the concept simply, then provide pages and pages of code with the end product which is “hello world”. Why I should go to all that trouble instead of simply writing <php echo 'hello world'; ?> to the screen usually escapes me. Dennis, however, concentrates solely on the Model and shows exactly why it’s a great idea. I think some more separation of concerns would have been better (don’t mix Author and Book SQL in the same object, for example), but the ideas were all good.

I think that if Dennis was going to show how the Model works, he should also have gone a little further and showed an example of an Active Record pattern as well. But I guess the point of showing MVC was more to show /an/ example of abstraction of the DB code, and that was sufficient.

The book covers a Library manager application all the way through from conception to implementation, demonstrating at all points that the code works with SQLite and MySQL (and by implication, all other DBMS’s) with a change of only the connection string.

Possible problems are explained clearly and solutions are provided. For example, Dennis explains why, after you compile the query select * from books, PDO (and indeed the database itself) does not know how many rows it will return. A solution, in the form of a very smart getRowCount() function shows a query-agnostic method for counting results of an arbitrary line of SQL.

Other areas that are covered in the book include error-handling, prepared statements and transaction-handling.

PDO can handle Prepared Statements even if the underlying DBMS cannot handle it, so it is possible to write your code in a cross-platform way. Examples of why you should use this are provided. One of the examples shows an efficient way to handle insertion or updating of a table using the same parameters for both cases, with the row-handling function deciding whether to use update or insert based on whether an ID was provided.

I feel the Transactions section could have been expanded a bit further. It is not explained how PDO handles this for DBMS’s that don’t internally support transactions, and I wouldn’t like to assume that they work all the time, only to find after deleting critical data that it’s not supported.

Overall, I enjoyed reading this book. Dennis is a good writer and I think he explained his thoughts very clearly.

On an aside, my four-year-old son Jareth loves Packt Publishing‘s books. Sometimes when I go to read another chapter, I need to covertly steal the book I’m reading back from him. For a while, he made it a bed-time ritual to grab all the Packt books he could find around and bring them up with him to read in bed. I think he loved the screen-shots and the frequent code samples. He’s high-functioning autistic and likes literary constructs, and programming books are perfect for him in that regard. Thanks Packt, you’ve made my son (and therefore me) happy.

15 Aug

online autism test hack

I was speaking with m1 in the ILUG chatroom today, and he mentioned an online autism test on Wired.com.

When you fill that out, and submit it, though, you will be shown the source code of the script which was supposed to calculate the results.

To get it to work, download the source, copy it into a .pl file, and upload it to your own server into your own cgi-bin (chmod to 755 before uploading). Then open up the test, use Firebug to edit the ‘action’ parameter of the form to point to your machine, and there you go!

If you want to try it out yourself, my copy of the file is here: http://verens.com/cgi-bin/autistic.pl – go to the wired.com form, change its action using Firebug (“inspect” the form, and click the action parameter to change it), then fill in the form and submit.

I scored 32, by the way, which is not quite the social animal I’m sure everyone takes me for, but also not extremely autistic. (of course, a few of those questions were confusing, so I may have got them wrong 😉 )

11 Aug


Today, I add a new tag to my wordpress collection.

Yesterday, Jareth’s psychiatrist, the jazz-playing Michael McDonough, verified that Jareth is autistic.

This was not a snap decision. Jareth has been in observation for over a year now. Almost every week, I’ve taken half a day off work to bring him to sessions at Enable Ireland. the Monaghan branch is very very friendly.

Some of the signs of his autism:

  • He will be four next month. He has not spoken a single sentence yet.
  • He expresses excitement by jumping up and down and flapping his hands
  • He has extraordinary sequencing ability – can write numbers from 0 to whatever, and letters from a to z. Also the reverse – z to a, whatever to 0.
  • His drawing ability is more complex than one would expect of a three year old.

There are more symptoms (see here for the more common characteristics), but they are not as visually obvious.

So why am I putting this in my blog? Surely one non-technical post this month is more than enough?

Well, if you are reading this blog, you are probably a technical person. And you probably exhibit those same characteristics. Are you very good in some areas (programming, for example) and other people think you are anti-social (even if you don’t think so yourself)? Do you fidget?

The reason I say all this is that I see myself in Jareth. As a child, I was always alone, I was nicknamed “Einstein II” because I had a great ability in maths and general knowledge (the maths ability stagnated as I got bored with school), I still fidget (rocking, finger tapping), people say I am antisocial and arrogant and even sometimes obnoxious although I really don’t see it at the time and am always surprised when someone says it.

Autism is about 80% genetic, and there is a 4.3:1 ratio of male to female incidence. this means that if Jareth’s autism is hereditary, then he most likely got it from me than from Bronwyn.

There is a plus side, though – I grew out of most of the symptoms, and I think he will as well.

Also, his abilities are perfect for the 21st century – his interests lie in areas that are perfect for engineering, programming, or other technical careers. I think he’ll go far.

Autism is not a bad thing. It is just another way of approaching life. There is no cure, but autistics say that they don’t want to be “cured” anyway.

My son enjoys his life, even if communication is frustrating, and I would not have him any other way.