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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器