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.

2 Responses 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.

  2. lingerie sexy says:
    11/9/2011 at 12:34 pm

    lingerie sexy…

    [...]PDO Design Evolution – Professional PHP[...]…

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 (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 [...]
  • Recent Posts

    • Richard Thomas
    • 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
  • Site

    • Archives
    • Log in
  • Search