Wordpress Multisite “Error establishing a database

2019-03-12 19:09发布

When attempting to convert WordPress to a Multisite setup, I get the error:

Error establishing a database connection

I'm using WordPress 3.7.1 on Windows 7 with a WAMP server.

wp-config.php

define('WP_ALLOW_MULTISITE', true ); 
define('SUBDOMAIN_INSTALL', false); 
define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/wordpress_test4/');
define('SITE_ID_CURRENT_SITE', 1); 
define('BLOG_ID_CURRENT_SITE', 1);

.htaccess

RewriteEngine On 
RewriteBase /wordpress_test4/ 
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin 
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^ - [L] 
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] 
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] 
RewriteRule . index.php [L]

标签: wordpress
11条回答
放荡不羁爱自由
2楼-- · 2019-03-12 19:30

I had a strange encounter very recently. After setting up a dev server which runs under a different domain and moving a multisite setup to it I got the same error “Error establishing a database connection”. I had checked that all the wp_options tables have the correct domains in the respective settings and that my database connection had the right credentials and would work under normal circumferences.

I found a way to get a better error reporting. I added an output of the database object in the function dead_db() in functions.php which then showed me that it couldn’t find any blogs for my site in the table wp_blogs. I simply forgot to update the domains for the test server in this table.

function dead_db() {
  global $wpdb;

  echo "<pre>";
  print_r($wpdb);
  echo "</pre>";

  wp_load_translations_early();

Hope that helps someone :)

查看更多
Rolldiameter
3楼-- · 2019-03-12 19:31

I struggled a long time because of this issue. And finally found a solution.

You should not add all those settings at once in the wp-config.php file. Follow the exact steps described here: http://codex.wordpress.org/Create_A_Network

Only add the following code as the first step:

/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );

And then refresh your page. After that, in your administration panel go to Tools -> Network Setup and choose your sub-site settings.

For the rest, just use the instructions from the link above.

Good luck!

查看更多
老娘就宠你
4楼-- · 2019-03-12 19:31

Inspired by Sabin's answer, I checked wp_blogs and found that the domain value was still pointing to the wrong domain (I was moving a multi-site to a dev server). Running UPDATE wp_blogs SET domain='example.com'; fixed my issue (note that I'm using subfolder multisite, not subdomain - don't blindly run that SQL!)

查看更多
叛逆
5楼-- · 2019-03-12 19:34

Here's How I fixed it

config settings

define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
define( 'DOMAIN_CURRENT_SITE', 'localhost' );
define( 'PATH_CURRENT_SITE', '/myblog/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

then in the database table (found using phpmyadmin) wp_blogs set the values for your root blog (which should be lie/number 1) to

domain localhost
root /myblog/

And finally - reset the sitrurl and homepage in options table (again found using phpmyadmin) to

 http://localhost/myblog/
查看更多
Juvenile、少年°
6楼-- · 2019-03-12 19:42

My DOMAIN_CURRENT_SITE in wp-config.php was define('DOMAIN_CURRENT_SITE', 'www.example.com');

Removing "http://" in wp_blogs -> domain fixed my issue.

查看更多
登录 后发表回答