2013-07-17 01:01
浏览 66


I'm trying to set up a new WordPress site and can't get it to connect to the database.

To to try isolate the problem, I created a php file in the same directory as the WordPress app with the following code:

$mysqli = new mysqli('localhost:3306', 'root', 'somepassword', 'gazos');

if ($mysqli->connect_error)
    die('Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error);
   echo 'Good connection to gazos';

When I execute it from the browser, it returns Good connection to gazos.

This the first part of my wp-config.php file:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'gazos');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', 'somepassword');

/** MySQL hostname */
define('DB_HOST', 'localhost:3306');

Calling the supplied WordPress index.php file results in the following error:

Error establishing a database connection

I get the same error when I remove the port from localhost.

Could the php version be too new for WordPress?

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

2条回答 默认 最新

  • duanchen7036 2013-07-18 00:09

    Replace localhost:3306 with

    When I asked this question on a wordpress forum, I was told my MySQL configuration was bad. When I asked about that problem on this forum, it was suggested that I try in place of localhost:3306. That fixed the problem. I still don't know if my configuration is bad.

    打赏 评论
  • douyunhuan9886 2013-07-17 17:04

    leave the port out on DB_HOST.

    define('DB_HOST', 'localhost');

    Edit: Try changing your mysql password and updating your wp-config.php.

    Saw that here.

    打赏 评论

相关推荐 更多相似问题