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 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题