dphfwzn8269
2014-04-23 12:18
浏览 47
已采纳

WordPress 3.9多站点数据库连接错误

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?

图片转代码服务由CSDN问答提供 功能建议

我安装了ZendFW应用程序和WPMU。 Zend应用程序的管理员有一个界面,可以创建一个新的MU站点。

我包含 wp-load.php ,然后调用 wpmu_create_blog 依此类推......

一旦我将WP更新为3.9,我就错误地建立了数据库连接。

此测试代码正常工作 3.8但尝试WP 3.9时会出现db错误。

blog38 是WP 3.8

 &lt;?php  
 
包括“../blog38/wp-load.php";
nlobal/wpdb; 
echo”&lt; pre&gt;“; 
var_dump($ wpdb-&gt; tables()); 
?&gt;  ; 
   
 
 

blog39 是WP 3.9

 &lt;?php 
 \  ninclude“../blog39/wp-load.php";
nglobal $ wpdb; 
echo”&lt; pre&gt;“; 
var_dump($ wpdb-&gt; tables()); 
?&gt; 
    
 
 

有谁知道问题是什么? 如何解决此连接错误?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhouzhang8696 2014-04-24 10:44
    已采纳

    I posted it on WordPress discussion and submitted a ticket as well. The problem is in ms-setting.php file with new way they set $path and $current_site->path variables. In WP 3.8.3 they had $current_site->path = $path = PATH_CURRENT_SITE;

    and in WP 3.9 they set

    $current_site->path = PATH_CURRENT_SITE;

    and $path is determined by the $_SERVER['REQUEST_URI'] variable. So when you load wp-load.php file inside your application (and wordpress is in subdirectory) you have $path and $current_site->path variable different which ends up in no blog defined case, which gives Database connection error.

    Current workaround is to override $_SERVER['REQUEST_URI'] = '/blog/'; before loading wp-load.php

    More information can be found:

    http://wordpress.org/support/topic/wordpress-39-multisite-db-connection-error https://core.trac.wordpress.org/ticket/27999

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题