dstjh46606 2013-07-17 01:01
浏览 68
已采纳

测试代码可以,WordPress无法连接到MySQL数据库

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:

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

if ($mysqli->connect_error)
    die('Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error);
else
   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:

<?php
// ** 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 127.0.0.1.

    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 127.0.0.1 in place of localhost:3306. That fixed the problem. I still don't know if my configuration is bad.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统