最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mysql - Error establishing a database connection,

programmeradmin1浏览0评论

I'm getting Error establishing a database connection when installing WP.

The following prints "Connected" when putting into wp-config.php:

$mysqli_connection = mysqli_connect(
  $_dbsettings['host'],
  $_dbsettings['user'],
  $_dbsettings['pass'],
  trim( $_dbsettings['path'], '/' ),
  $_dbsettings['port']
);

if ($mysqli_connection->connect_error) {
   echo "Not connected, error: " . $mysqli_connection->connect_error;
}
else {
   echo "Connected.";
}

What's going on?

Update:

I use heroku-wp, more about the wp-config.php here.

I'm getting Error establishing a database connection when installing WP.

The following prints "Connected" when putting into wp-config.php:

$mysqli_connection = mysqli_connect(
  $_dbsettings['host'],
  $_dbsettings['user'],
  $_dbsettings['pass'],
  trim( $_dbsettings['path'], '/' ),
  $_dbsettings['port']
);

if ($mysqli_connection->connect_error) {
   echo "Not connected, error: " . $mysqli_connection->connect_error;
}
else {
   echo "Connected.";
}

What's going on?

Update:

I use heroku-wp, more about the wp-config.php here.

Share Improve this question edited Feb 23, 2020 at 22:20 haxpanel asked Feb 21, 2020 at 19:25 haxpanelhaxpanel 15710 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Maybe if you configured the wp-config.php file like the documentation says (see https://wordpress/support/article/editing-wp-config-php/ )

Sample wp-config.php file (database section), per the above link:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Your code is proper for making a 'manual' connection to the database, but it does not set the DEFINES that WP will use for connections.

Apart from the check that you have to do with your WordPress Database Credentials, also you can check and repair your database

Navigate to your root WordPress file directory and find the wp-config. This file contains your WordPress installation settings and configuration. You can add this line of code of the bottom :

define( 'WP_ALLOW_REPAIR', true );

This line will enable you from one hand to optimize and on the other hand to repair your database by navigating to www.yourwebsite/wp-admin/maint/repair.php (you can replace the “yourwebsite” with your actual URL). Then will see a screen with two options repair database and repair and optimize your database. Feel free and choose your option, but the option of repair and optimize will take longer.

In the end, please keep in mind that the database repair page is not secure because anyone can access that URL without having to login. Once you have done with this process and you are done repairing your database, then be sure to remove the line of code you added to wp-config, I refer to define( 'WP_ALLOW_REPAIR', true );

发布评论

评论列表(0)

  1. 暂无评论