WPDB include problems in wordpress 3.0

From time to time my brain remembers me that there is a major bug within wordpress in case of the re-instantiation of the wordpress database class. When a replacement class is in use, the original WPDB one will get re-created under certain circumstances instead of the replacement one. That breaks the modular DB replacement concept once introduced.

This bug is not widely known because right now not many users are replacing the database class. With wordpress 3.0 it will become more popular to replace it because currently it got replaced in the MU merge with a hyper-mega-f!#$-db (say it with scooter: hyper, hyper!) which just has an enormous overhead in single-site setups and contains of a lot of legacy code.

Just to remind: previous to the merge I did some overwork of the wpdb class for development purposes (refactoring, improvements, security, stability, optimization and all that stuff) and since the 3.0 release is comming closer, those deficiencies will be quite a hot topic sooner or later. You must imagine that the MU class is based on even older code, so this will be fun.

I wish we get the replacement related bugs out in 3.0 so that everybody is able to use the wpdb implementation she or he likes best without any flaws in the (currently broken) API. Go Go Gadget.

This entry was posted in Hacking The Core and tagged , , , , , , . Bookmark the permalink.

4 Responses to WPDB include problems in wordpress 3.0

  1. Pingback: It's coming! WordPress 3.0 - Pros and Cons - Template Monster Blog

  2. uwiuw says:

    i haven’t encounter the problem. Maybe it’s more because i haven’t done using $wpdb as much as you do. But certainly this become relevant to me cause i have to code clone of wpdb and make it access the different database. is it this possible to do this without encountering any bugs ?

    • hakre says:

      You should give it a try. Right now from what I’ve seen in the trunk-code the way of including the file has been improved allowing to fully overload the whole wpdb class.

      This at least adresses my concerns I adressed in this post quite well.

  3. Shanu says:

    Try this one

    #To allow this to be as extensible as possible, make sure $table_prefix is globalised, we also need the $wpdb class functions too
    global $table_prefix, $wpdb;

    #Create the ‘name’ of our table which is prefixed by the standard WP table prefix (which you specified when you installed WP)
    $wp_track_members_table = $table_prefix . “wp_track_members”;

    #Check to see if the table exists already, if not, then create it
    if($wpdb->get_var(“show tables like ‘$wp_track_members_table'”) != $wp_track_members_table) {

    $sql0 = “CREATE TABLE `”. $wp_track_members_table . “` ( “;
    $sql0 .= ” `page_load_id` int(11) NOT NULL auto_increment, “;
    $sql0 .= ” `todays_date` date NOT NULL default ‘0000-00-00′, “;
    $sql0 .= ” `todays_time` time NOT NULL default ’00:00:00’, “;
    $sql0 .= ” UNIQUE KEY `page_load_id` (`page_load_id`) “;

    #We need to include this file so we have access to the dbDelta function below (which is used to create the table)
    require_once(ABSPATH . ‘wp-admin/upgrade-functions.php’);

    # The Hook – you can choose which hook you want to use, for this instance, we’ll run this script every time the footer is loaded
    add_action(‘wp_footer’, ‘createtable_wp_track_members’);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.