Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t从php连接到远程Mysql服务器 客户端系统:CentOS Linux 7.0.1406版(核心版) 客户端Ip:222.222.222.222_Php_Mysql_Linux_Centos - Fatal编程技术网

Can';t从php连接到远程Mysql服务器 客户端系统:CentOS Linux 7.0.1406版(核心版) 客户端Ip:222.222.222.222

Can';t从php连接到远程Mysql服务器 客户端系统:CentOS Linux 7.0.1406版(核心版) 客户端Ip:222.222.222.222,php,mysql,linux,centos,Php,Mysql,Linux,Centos,查看ip 222.222.222.222 服务器系统:Gentoo基本系统版本1.12.13 服务器ip:111.111.111.111 连接的脚本: $connection = new \mysqli('111.111.111.111', 'user', 'password', 'db'); if (mysqli_connect_error()) { echo "Error: {$connection->connect_error}"; } else { echo "

查看ip 222.222.222.222

  • 服务器系统:Gentoo基本系统版本1.12.13

  • 服务器ip:111.111.111.111
  • 连接的脚本:

    $connection = new \mysqli('111.111.111.111', 'user', 'password', 'db');
    if (mysqli_connect_error()) {
        echo "Error: {$connection->connect_error}"; 
    }
    else {
        echo "Server Info: {$connection->server_info}";
    }
    
    当我试图在浏览器“”中打开时,我得到:

    。。。但是,当我从服务器222.222.222.222上的命令行启动此脚本时,我得到了另一个结果:

    /usr/bin/php /var/www/reporter/test.php
    Server Info: 5.5.14-enterprise-commercial-advanced-log
    
    直接从命令行连接也正确:

    mysql -h 111.111.111.111 -u user -p -P 3306
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MySQL connection id is 25236357
    Server version: 5.5.14-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)
    
    Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    



    回答
    客户端环境问题-Centos中的Selinux。修复它的命令:

    setsebool -P httpd_can_network_connect=1
    
    setsebool -P httpd_can_network_connect=1
    

    客户端环境问题-Centos中的Selinux。 修复它的命令:

    setsebool -P httpd_can_network_connect=1
    
    setsebool -P httpd_can_network_connect=1
    

    检查防火墙、suhosin/selinux阻塞之类的东西,诸如此类。非常确定错误13是一个权限问题。仔细检查PHP中的密码以确定是否正确?为什么这一行有反斜杠-
    new\mysqli('111.11
    ?@JayBlanchard全局名称空间,可能不必要,但我觉得这是一个很好的做法…以防他在当前名称空间中声明了一个新的mysqli函数。请参见此处的示例Marc B,用户存在,端口打开-我可以远程连接到DB。我甚至可以连接到使用相同的文件,但只能从cimmand行,我不知道为什么会出现这种行为。rjdown、用户和密码是正确的-我从浏览器和命令行启动相同的脚本,但连接仅从命令行建立。非常感谢!