Professional PHP Blog

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.

php | architect back issue bargains

January 6th, 2007

I’ve been writing the Test Pattern column in php | architect for a few months now. I’ve been enjoying it because it lets me explore topics in more depth than I could here on my blog. Although, its more challenging and writing is not easy for me.

So far I think my best two columns have been Organizing For Change and Dependency Injection. These are my favorites at least.

Why do I bring this up? Because today, as part of their 7 day promo fest, back issues are 50% off. That means you could pick up the back issues with my best columns for a measly $1.99 a piece in PDF form. (He blogs shamelessly.) I put a lot of effort into those columns, I’m proud of them and I want you to read them. :)

5 Comments »

Looking forward to 2007

January 4th, 2007

Well, I’m finally back in town after the holidays. Let me tell you, I’m glad to be home. Between multiple holidays and taking my grandma to her cancer treatments in Ann Arbor, I was gone far too much of last month.

My Grandma is doing well. They used an experimental new procedure called radio frequency ablation to remove the meta-static colon cancer tumors from her lungs. This procedure is amazing compared to the standard treatment. The doctors at the University of Michigan were impressive. We’ll know the results in a couple months when her lungs look a little less like scrambled eggs. We’re hopeful.

I’m not much for retrospectives. Looking forward into 2007, I have a few major goals. I joined a gym today. I’m going to get a new laptop and refresh my development environment next week after MacWorld. I want to get at least a beta release of WACT out by May. I have to prepare for php|tek. I need to find a new place to live by this fall. (Ann Arbor?) I want to move by the end of the year.

I loved all my christmas and birthday gifts this year. (My birthday is December 28th.) This year I pointed everyone to my Amazon.com wishlist and I ended up with a ton of good books to read. Jason Gillmore from Apress also sent me some web development books. My to-read stack for 2007 includes:

  • The Promise of Sleep – A survey of the subject of sleep for laymen, written by a top sleep researcher. I’m almost done with this one. This book has a bunch of sleep deprivation horror stories and a good survey of what is known about sleep, which is not much. Its incredible that we know so little about something we spend so much time doing. Its also amazing how many people have easily treatable sleep disorders that don’t even know it. Do you snore?
  • Don’t make me Think – Looks like a nice overview book on web usability.
  • Domain Driven Design – Recommended by Jason and Marcus. How did I get this far without reading this book?
  • Da Vinci Code – Wasn’t on my wishlist, but I’ll read it anyway. I read so little fiction these days. Where is a beach when you need one?
  • Getting Things Done – I’m almost through this one. It is a testimony to the power of the ideas that this book expresses that so many people recommend it, despite its being so incredibly dull. Useful? Yes. Inspiring? No. But, then I’ve read enough of these self help / personal productivity type books for a lifetime. Anyone want to buy a Franklin Planner? I used mine until I got a cell phone.
  • Practical Subversion – I’m really liking subversion. If you haven’t tried it, do so. I’m hoping to combine this with Greg Beaver’s book, The PEAR installer manifesto — the book on my wishlist I most wanted that I didn’t get, to create a new deployment process.
  • Pro CSS Techniques – A CSS book that tackles maintainability? I’m really looking forward to this one.
  • Pro MySQL – The last MySQL book I read was a couple years ago, yet I use it almost every day. I’m due for a refresh. This one looks good.
  • Pro PHP Security – Never hurts to brush up. This one looks like it has alot on encryption, SSL and SSH; not strong areas for me.
  • Pattern-Oriented Software ARchitecture Volume 2 – The first volume, A system of patterns, is one of my “always within reach when developing” books. Nice to add to the set.

Thanks for the books, guys. I’ll have in-depth reviews of some of these here in the future.

Happy New Year.

9 Comments »

PDO versus MDB2

December 26th, 2006

I was just putting together a small test program and I thought I would try using PDO. I really haven’t done anything serious with PDO, just try it a couple times. After recompiling PHP to include the mysql driver for PDO, I coded up the first version of my test program:

 
$db = new PDO('mysql:host=localhost;dbname=example', 'example', 'secret');
 
$tags = $db->prepare("
    SELECT 
        * 
    FROM 
        bookmark_tags, tags 
    WHERE 
        bookmark_tags.bookmark_id = ? AND 
        tags.id = bookmark_tags.tag_id 
    ORDER BY 
        tags.name");
 
$bookmarks = $db->prepare("SELECT * FROM bookmarks ORDER BY Title");
$bookmarks->execute();
while ($bookmark = $bookmarks->fetchObject()) {
    echo "<li><a href='{$bookmark->url}'>{$bookmark->title}</a> ";
    
    $tags->execute(array($bookmark->id));
    while ($tag = $tags->fetchObject()) {
        echo $tag->name, " ";
    }
 
    echo "</li>\n";
}
echo "\n";
 

Unfortunately, this didn’t work and it took me a few minutes to figure out why. Actually, I still don’t know exactly why it doesn’t work, but I did find a way to make it work: by using two separate connections, one for each prepared statement. It doesn’t seem like you can have two active statements at the same time on the same connection. I find this hard to believe, so I’m probably doing something wrong.

The other thing I didn’t care for with this PDO code is the non-standard method of iteration with the while loop. Well, the while loop is perfectly standard if you are coming from the PHP 4 style functional DB APIs. However, it doesn’t seem to fit in with the PHP 5 Iterator and foreach integration. PDO doesn’t seem to provide a distinct result set object, or a method of iterating over a result set using the standard PHP Iterator interface.

Now, I can understand why this may be the case. The PDO interface seems to be designed to bind to php variables. Thats not going to work with the Iterator interface. However, I am not using that mode and don’t want to use that mode. It would be nice to be able to acquire an iterator for an example of use such as the one above without having to use fetchAll and ArrayIterator.

Using the Iterator style makes it easier for me to decouple my code from the data source and makes it easier to write test cases for that code.

I was a little bit disappointed. So I moved on to MDB2 with the same code …

 
require_once 'MDB2.php';
require_once 'MDB2/iterator.php';
 
$db = MDB2::connect("mysql://example:secret@localhost/example");
 
$tagLookup = $db->prepare("
    SELECT 
        * 
    FROM 
        bookmark_tags, tags 
    WHERE 
        bookmark_tags.bookmark_id = ? AND 
        tags.id = bookmark_tags.tag_id 
    ORDER BY 
        tags.name");
 
$bookmarkFinder = $db->prepare("SELECT * FROM bookmarks ORDER BY Title");
$bookmarks = new MDB2_Iterator($bookmarkFinder->execute(), MDB2_FETCHMODE_OBJECT);
    
echo "<ul>\n";
foreach($bookmarks as $bookmark) {
    echo "<li><a href='{$bookmark->url}'>{$bookmark->title}</a> ";
 
    $tags = new MDB2_Iterator($tagLookup->execute($bookmark->id), MDB2_FETCHMODE_OBJECT);
    foreach($tags as $tag) {
        echo $tag->name, " ";
    }
 
    echo "</li>\n";
}
echo "</ul>\n";
 

I have about the same level of non-experience with MDB2 as with PDO, but my code worked perfectly on the first try and allowed me to use Iterator, which will be helpful to the next stage of my test.

I was a bit impressed. I’ll see how well it handles the next stage of what I want to do.

(And yes, I know there is no error checking in the above code.)

39 Comments »

Why is PHP Code Considered Hard to Maintain?

November 9th, 2006

Tobias Schlitt describes Tim Bray’s talk at the International PHP Conference. (PDF slides) Tim compares PHP, Java, and Rails along several dimensions. One of those dimensions is maintainability. Tim ranks PHP as least maintainable, Rails in the middle, and Java as most maintainable.
This is not a surprising ranking. [...]

48 Comments | Read the full post »

PHP as a Deployment Platform

November 4th, 2006

PHP has been incredibly successful as a deployment platform for web applications. The WordPress blog brags that the WordPress 2.0 series has been downloaded 1.2 million times.
However, PHP as a platform is far from homogenous. With many different versions installed and the vast configurability of php.ini, there can be a great [...]

28 Comments | Read the full post »

Faster Page Loading

October 31st, 2006

Google engineer Aaron Hopkins wrote a good article on page loading times (via Harry). He talks about the impact of AJAX on page load times, focusing on connection limits, latency and the large number of external objects on your typical AJAX page. He offers a variety of tips on improving page [...]

7 Comments | Read the full post »

The Legality of Republishing RSS Feeds

July 20th, 2006

Tobias Schlitt “freaked out” today about PHP Freak’s republishing of his blog feed. He publicly withdraws his implicit permission for PHP Freaks to republish content from his feeds.
This is an interesting area of law. Eric Goldman has an rundown of the issues.
In my mind, there’s no question that a blogger grants an implied [...]

36 Comments | Read the full post »

Meta Tag Refresh Faux Paux

July 17th, 2006

If, for some unfathomable reason, you put a meta tag refresh on every page of your site, you may want to consider not putting it on any page with a form on it. Especially a long complicated form. 30 minutes may seem like a long time to fill out a form, but sometimes [...]

23 Comments | Read the full post »

The Paradox of Choice

July 13th, 2006

I don’t like to just link to stuff, but outsourcing choice at 37 signals is worth linking to. The post talks about designing interfaces with fewer choices. Really, the interesting thing here is Barry Schwartz and his book, The paradox of Choice. The paradox of choice being that having more choices makes [...]

6 Comments | Read the full post »

un-PEAR-ing

July 5th, 2006

Astonishing. I’m quite surprised. I thought PHPUnit was fairly well integrated into PEAR (pear run-tests). I’m not sure if this is a fork, or if PEAR will continue to use PHPUnit as an external dependency?
I’ve never been a PEAR fan. My experiences being peripherally involved with the XML_HTMLSax package weren’t [...]

10 Comments | Read the full post »

« Previous Entries
Next Entries »
    Subscribe Feed
    Share Subscribe to this blog…
    Share Bookmark or share this page…
  • About

    My name is Jeff Moore. I'm a PHP programmer living in San Francico and working for a startup.

    More about me…

  • Categories

    • Agile Methods (14)
    • Mac (14)
    • Misc (18)
    • Open Source (14)
    • PHP (99)
    • Software Design (29)
    • Usability (14)
    • Web Design (20)
  • Recent Comments

    • Why PHP is easier to learn than Java  51
      Brant Chamorro, Jay Marry, Jutta Trudel [...]
    • On the Perils of Inline API Documentation  16
      Glen Hollinger, Newton Boudoin, Chaussre Air Jordan [...]
    • un-Friendster: fired for blogging  5
      Un Hawse, Jim Skomo, Analisa Niccum [...]
    • PHP Book sales trends versus Java and Ruby  7
      Rosann Frederick, Glenn Leffingwell, byb bye blemish [...]
    • Let Your Properties be Properties  17
      Lupita Ziler, Lawrence Constanzo, nail dryer [...]
    • Upgraded to WordPress 1.2  3
      Laurence Morda, Ike Mcleish, Vilma Babers
    • PHP Coding Standards  12
      Twana Ventry, Luther Quelch, Rhett Ososki [...]
    • Commercial Zend versus Open Source PHP  11
      Loria Brendel, Billie Areola, Hans Stremmel [...]
    • A WordPress bug fix  7
      Malcolm Kinnon, Maximo Caoagdan, Kali Giesbrecht [...]
    • The PHP scalability saga continues  17
      Cameron Borah, Monty Gucciardo, Freddie Leaton [...]
  • My Other Stuff

    • Lively Debate
      My blog on Politics and non-technical topics
    • Web Application Component Toolkit
      PHP MVC Framework
  • Other PHP Blogs

    • Dynamically Typed
    • Jason E. Sweat
    • John Lim
    • Marco Tabini
    • Marcus Baker
    • Norbert Mocsnik
    • PHP Patterns
  • Site

    • Archives
    • Log in
  • Search