• Resolved touisk

    (@touisk)


    Hi,

    My blog was ok whith WordPress 3.0.4 and pg4wp 1.1.0 until I updated to wordpress 3.1 !

    PHP logs shows a PHP Fatal error:  Cannot redeclare class wpdb in /usr/share/wordpress/htdocs/wp-content/db.php(37) : eval()'d code on line 52

    In wordpress 3.0.5 the require_wp_db(); – call in the /wp-settings.php – is implemented in the file /wp-includes/functions.php which is :

    function require_wp_db() {
            global $wpdb;
            if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
                    require_once( WP_CONTENT_DIR . '/db.php' );
            else
                    require_once( ABSPATH . WPINC . '/wp-db.php' );
    }

    The class wpdb – in /wp-includes/wp-db.php – is evaluated by the eval function in /wp-content/db.php file from pg4wp :

    eval( str_replace( array_keys($replaces), array_values($replaces), file_get_contents(ABSPATH.'/wp-includes/wp-db.php')));

    The evaluation is done after the replacement of MySQL names to postgres ones.

    But in WordPress 3.1, require_wp_db() function has moved into the file /wp-includes/load.php. The new implementation is :

    function require_wp_db() {
            global $wpdb;
    
            require_once( ABSPATH . WPINC . '/wp-db.php' );
            if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
                    require_once( WP_CONTENT_DIR . '/db.php' );
    
            if ( isset( $wpdb ) )
                    return;
    
            $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
    }

    in those conditions; /wp-includes/wp-db.php is evaluated twice ! with the wp-content/db.php. The class wpdb can not be redeclared twice.

    My solution is to … come back. I simply re-implemented the WP 3.1 require_wp_db() function like this :

    function require_wp_db() {
            global $wpdb;
    
            if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
                    require_once( WP_CONTENT_DIR . '/db.php' );
            else
                    require_once( ABSPATH . WPINC . '/wp-db.php' );
    
            if ( isset( $wpdb ) )
                    return;
    
            $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
    }

    Hope, this could help …

Viewing 16 replies (of 16 total)
  • Hello

    I’m currently updating PG4WP make it fully compatible with WordPress up to version 3.2.1

    I’ve released a beta that works ok on my setup, if you want to give it a try you’ll find a direct link on https://www.hawkix.net.

    If upgrading PG4WP from any earlier version, don’t forget to replace the db.php file with the one from the pg4wp/ directory.

    Beta 1.2.0b1 should at least have all the issues found in this topic resolved.

Viewing 16 replies (of 16 total)
  • The topic ‘WP 3.1 – pg4wp – Cannot redeclare class wpdb’ is closed to new replies.