Professional PHP

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.
« Bad Code Smells in WACT, a refactoring review
Status of WACT »

PDO Design Evolution

October 23rd, 2004

Alan Knowles has an interesting post on PDO.

I really don’t know much about PDO, i haven’t used it yet. Most of what I know comes from:
Wez Furlong’s first steps with PDO examples
Wez’s Oracle PDO Article
John Lim’s discussion of adodb and PDO
A sitepoint thread on PDO
I haven’t seen any API type docs yet. I did download an older version of the PECL code and skim through it.

Alan has some interesting things to say. I have to agree with him on using libgda as a back end. Using a more mature, existing, debugged code base seems very reasonable to me. Could libgda be used as the PDO back end while retaining the PDO front end API?

When I first looked at PDO, the parameter binding is one of the things that really jumped out at me. It reminded me of register globals, a technique that didn’t necessarily turn out well and was painful to back out of. Now that Alan says it, this technique is a bit more reminiscent of C than PHP. As i understand its an optional way to use PDO. A way that I would not use.

Wez comments:

- copying C: I agree that bound parameters can lead to magic code. There are two things to keep in mind: a good coding style (with comments) is the best remedy for code that might be considered magic.

I have to strongly disagree on the coding style point. Salting magic code with comments does not make it palatable. The solution is to remove the magic.

I am not familiar enough with PDO to understand the iterator argument. None of the examples I have seen actually use iterators.

What I would like to see out of a basic OO DB API in PHP is better support for translating the database record into an object. For example, the fetch(PDO_FETCH_OBJ) method returns an anonymous object. I would like a way for this method to construct an object of a particular class along with an initialization protocol such as unserialize has with objects.

I do think that PDO should be a part of core PHP, but perhaps one with a more mature libgda backend and a more evolved PHP front end API, influenced by Alan’s feedback and DBDO efforts.

I have noticed that sometimes the API design in PHP tends to simply wrap underlying 3rd party C libraries, even when that design doesn’t make the most sense in PHP. (for example the PHP wrapping of expat) PDO is a more of an attempt to design a PHP oriented API and then work the 3rd party libraries into the common design. To me, this is a step forward. However, the PDO API probably needs to go through a few iterations as Alan suggests before being frozen into core PHP.

Filed Under

  • PHP, Software Design

Related Posts

  • No related posts
You can leave a response, or trackback from your own site.

One Response to “PDO Design Evolution”

  1. Lukas says:
    10/24/2004 at 3:23 am

    Being able to dump the fetched data into a specific class or into an already existing instance was certainly on the todo list a while back. I dont know if it has been written yet.

Leave a Reply

Click here to cancel reply.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

code: use [code=php][/code].

Comment Preview

    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 (Home)

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

    • Programming Language Trends via Google  19
      Craigslist pva, jessica, Scott [...]
    • Looking Towards the Cloud  35
      bentonville multiple listing, cosmetic dental, Sam Brodish [...]
    • PHP versus ASP  8
      Marhta Blight, Ravi, Ryan Brooks [...]
    • How to Transfer Mac OS X Application Data between Computers  59
      Website Migration, harry the computer support guy, Dotty Salvage [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  157
      lehuuphuc, Robert Parthemer, Lingerie Intimate [...]
    • PHP Games  25
      jessica, Tennille Cranor at Chilli Plants, Lucas Ortell [...]
    • un-PEAR-ing  5
      jessica, Eugene Panin, Arnaud [...]
    • The Legality of Republishing RSS Feeds  23
      kevinxiao, Marissa Miscovich, Quick Student Loans [...]
    • Faster Page Loading  4
      jessica, angular cheilitis, Aaron Rosenfeld [...]
    • PDO versus MDB2  15
      jessica, kevinxiao, Gavin [...]
  • Recent Posts

    • ZendCon: Writing Maintainable PHP Code
    • Looking Towards the Cloud
    • Holiday Tech Support
    • Closures are coming to PHP
    • php | tek Wrapup
    • php | tek 2008
    • Sarah Snow Stever
    • Benchmarking PHP’s Magic Methods
    • The Endpoints of the Scale of Stupidity on Video
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)
  • Site

    • Archives
    • Log in
  • Search