• I have a ZendFW application and WPMU installed. Admins at Zend app has an interface where they can create a new MU site.

    I included wp-load.php and then called wpmu_create_blog and so on…

    Once I updated the WP to 3.9 I got error establishing database connection.

    This test code works OK with 3.8 but gives db error when tried WP 3.9.

    blog38 is WP 3.8

    <?php
    include "../blog38/wp-load.php";
    global $wpdb;
    echo "<pre>";
    var_dump($wpdb->tables());
    ?>

    blog39 is WP 3.9

    <?php
    include "../blog39/wp-load.php";
    global $wpdb;
    echo "<pre>";
    var_dump($wpdb->tables());
    ?>

    Does anyone know what the problem is? How to solve this connection error?

Viewing 11 replies - 1 through 11 (of 11 total)
  • It seems that you have two different WP instances, 3.8 and 3.9, correct? Are you sure your WP 3.9 instance is functioning properly? Access the WP console to make sure.

    Thread Starter ivanbajalovic

    (@ivanbajalovic)

    WP 3.9 works properly. I can create new multi site, write post etc.. But when I try to enable any wp feature on my website (by including wp-load.php) I have problem with WP 3.9. The same code works ok with 3.8 version.

    As I dug a little deeper it seems like $wpdb is NULL.

    Your script is correct. I tested it on my WP 3.8 and 3.9 instances. The only problem is if you do not place the script in the proper directory relative to WP 3.9. IMO, the include is not finding wp-load.php (first line).

    Thread Starter ivanbajalovic

    (@ivanbajalovic)

    The directory path is OK. This code snippet is just to demonstrate the problem. In production, I did not change controller in Zend FW, I just updated WordPress and the error started to pop out…

    I think I found where the problem is. In wp-includes/ms-settings.php on line 56 there is an if statement

    if ( $current_site->domain === $domain && $current_site->path === $path )

    $current_site is Stdclass object, and domain and path attributes are set to (for my above example on localhost): domain => localhost, path => blog39 but the $path variable has value of “testblog” (this is the folder where this test file is located). Because condition is false $current_blog variable is set to null which gives the connection error.

    Because the path from where I include wp-load.php does not belong to any multi site that is created, I am getting this error.

    Any idea how to find a fix to this? Or the WordPress dev crew did this on purpose?

    Thread Starter ivanbajalovic

    (@ivanbajalovic)

    In WordPress 3.8 they set $path like this:

    $current_site->path = $path = PATH_CURRENT_SITE;

    where $current_site is Stdclass object.

    In WordPress 3.9 they set $path like this:

    $path = strtolower( stripslashes( $_SERVER['REQUEST_URI'] ) );
    	if ( is_admin() ) {
    		$path = preg_replace( '#(.*)/wp-admin/.*#', '$1/', $path );
    	}
    	list( $path ) = explode( '?', $path );
    ....
    $current_site->path = PATH_CURRENT_SITE;

    In WP 3.9 they set $path based on URL and $current_site->path based on constant PATH_CURRENT_SITE. This is the essence of the problem.

    Should this be treated as a bug?

    Hi @ivanbajalovic. Can you provide a few more details so that I can try to reproduce this issue?

    First, the path comparison should only be causing an issue if multisite is enabled with something like the MULTISITE constant. Can you confirm that this constant is set before you include wp-load.php?

    When it does fail, what are the values for $current_site, $current_blog, $path, $domain, $_SERVER['REQUEST_URI'], and $_SERVER['HTTP_HOST']?

    Something like this should do it:

    <?php
    include "../blog39/wp-load.php";
    global $current_site, $current_blog, $path, $domain;
    echo "<pre>";
    var_dump( $current_site, $current_blog, $path, $domain, $_SERVER['REQUEST_URI'], $_SERVER['HTTP_HOST'] );
    echo "<pre>";
    ?>

    @ivanbajalovic – I was able to reproduce your issue—I believe—and left a comment on the ticket explaining my thoughts.

    I think your best long term solution here is to handle the setting of $current_site and $current_blog with expected data before loading wp-load.php.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    It’s not a bug, it’s part of the upgrades put into Multisite to make it allow for any kind of set up.

    Read through https://make.www.ads-software.com/core/2014/04/16/multisite-changes-in-3-9/

    As far as I’m concerned this IS a bug – at least its totally broken my site which is used by around 9000 staff and students at a University.

    We are also running multisite in a subfolder, alongside some custom PHP pages in the root and as of upgrading to 3.9 the whole site (apart from the wordpress element) is down.

    I’m amazed nobody spotted this before release, and came up with an adequate solution before release.
    This page of the codex is now out out of date:
    https://codex.www.ads-software.com/Integrating_WordPress_with_Your_Website

    As this DOES NOT WORK running multisite in a sub folder.

    Jeremy, you mention setting the current_site and current_blog before loading wp-load.php.

    Can you please expand on this? Do you have a workaround I can use? Ideally something I can copy and paste into a file somewhere.

    Thanks!
    Alex

    Alex, could you try my workaround at https://core.trac.www.ads-software.com/ticket/29678

    Hi sgissinger,

    Thanks for the reply!
    Don’t worry – I have a more elegant solution I think.
    Details below:
    The Problem
    Running custom php pages that are including the wp-blog-header.php break when upgrading to WP 3.9. This only occurs if you are running a multisite in a subfolder e.g. “www.mysite.com/sites/”

    The Solution
    1. Create (if not already exist) the sunrise.php page in the wp-content folder.
    2. Add define( ‘SUNRISE’, ‘on’ ); to the wp-config file
    3. Add the following code to the sunrise.php file:

    if (strpos($_SERVER[‘REQUEST_URI’],’/sites’) === false)
    {
    $_SERVER[‘REQUEST_URI’] = ‘/sites/’;
    }

    This way it only overrides the request_uri on NON wordpress pages, which enables you to load the wp-blog-header.php correctly and also prevents all regular WP pages from redirecting to the root.

    It worked for me, and most importantly I understand it!
    Also, you’re not hacking around the core WP code so it will still work when you upgrade.

    Sounds like you hit exactly the same issues as me here:
    https://www.ads-software.com/support/topic/upgrading-broke-my-wp-integrated-site?replies=13

    Alex

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘WordPress 3.9 Multisite db connection error’ is closed to new replies.