dragon201401 2017-02-07 17:12
浏览 50
已采纳

PHP没有连接到远程MySQL

I need to connect to a remote MySQL server with PHP but I get the following error:

Warning: mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on ... (13) in /var/www/html/index.php on line 16

Warning: mysqli::query(): Couldn't fetch mysqli in /var/www/html/index.php on line 17

Fatal error: Call to a member function fetch_assoc() on a non-object in /var/www/html/index.php on line 18

The remote server firewal is open, user has permission to connect from any Host, and I'm able to connect from the local server with mysql command line, but not able to connect with PHP.

What may be the problem here?

EDIT: Already tried with different connection code, but always same error.

This is the latest one:

$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS msg");
$row = $result->fetch_assoc();
echo $row['msg'];
  • 写回答

2条回答 默认 最新

  • douhuan6065 2017-02-07 17:31
    关注

    Found this to be an issue with SELinux that is not allowing httpd network connections.

    Executing:

    setsebool -P httpd_can_network_connect=1
    

    Solved the problem.

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

报告相同问题?

悬赏问题

  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上
  • ¥15 装完kali之后下载Google输入法 重启电脑后出现以下状况 且退不出去 桌面消失 反复重启没用