WordPress.org

Forums

Use PDO instead of WPDB ??? (2 posts)

  1. AliceWonderFull
    Member
    Posted 12 months ago #

    Hi, I don't do a lot of WordPress programming but I do a lot of web programming and I always use PDO for my database abstraction.

    Biggest advantage, PDO lets the person running the app decide what database backend they want to use. For example, they may prefer PostgreSQL because they do stuff with GIS and need its spatial relations features.

    And looking at the WordPress $WPDB documentation, so far I find several things that PDO does better and not a single thing that WPDB does better. The placeholder for prepared queries being a simple example, with PDO you can just use a ? and don't have to worry about the data type or using %% where a % is a legitimate part of the query.

    Since PDO is an object, you can still do things like

    $pdo->tableprefix = 'foo_';

    to make the table prefix available to plugins that need it.

    Is there a reason I'm just not seeing as to why WordPress uses its own database abstraction that is tied to a single database over using something like PDO?

    It seems to me that using PDO would not only open up the database backend options, but also would reduce the code that has to be maintained by the WordPress developers.

    If there is something I'm just not getting, what is it?

  2. AliceWonderFull
    Member
    Posted 12 months ago #

    http://codex.wordpress.org/Using_Alternative_Databases#Solutions/

    doesn't even mention PDO - which alleviates the problems that page claims.

    It does mention a couple, but -

    These tools create large dependencies and break legacy plugins that depend on MySQL specific functions.

    Sometimes, but that's why you do it in a major version release. And once it is done, you don't continue to get new plugins written with database engine specific functions that are not standard SQL.

    Large generic database (and persistent object) abstraction implementations tend not to be exceedingly fast and may not use optimizations that could benefit specific databases.

    I'd be willing to bet pdo is faster than $WPDB

    This option will be a lot more work (likely less than implementing a WP-specific layer, however) and will require developers of the main project and plugins to be familiar with the abstraction layer chosen.

    So instead you make your own script based abstraction layer that you make everyone learn?

    PDO has been around a long time and is very well documented. A lot of people know how to use it.

    Much diligence will be necessary for developers to ensure that database-specific code doesn't make it into queries despite the abstraction layer, and this goes for plugin developers too.

    You mean developers actually have to check their code? Oh wow, yeah, I can see why that would be a problem...

    Some functionality can't be abstracted easily with ADODb or (to a much greater extent) PEAR; if WordPress uses this functionality, it may have to be reimplemented application-side, which would be a performance hit

    You don't want to use PEAR, PDO though is very good and actually is able to emulate many features that some databases don't have.

    The biggest performance hits though are actually excessive queries of what can and should be cached.

    Suggesting there might be a performance hit is making an argument that needs to be demonstrated when / where it is an issue, for most things it probably is not and where it is an issue, it probably can be fixed. If there even are issues.

    -=-=-=-

    Well, talking to myself.
    I just think WordPress would be a lot better if it used PDO - and DOMDocument but that's another topic ;)

Reply

You must log in to post.

About this Topic