2014-11-24 209 views
1

腳本用於連接:

$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}"; 
} 

當我試圖在瀏覽器中「http://test.com/test.php」打開,我得到:

Error: Can't connect to MySQL server on '111.111.111.111' (13) 

...但是當我開始從命令行這個腳本在服務器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. 




回答


問題與客戶端的環境 - SELINUX於CentOS。命令fo修復它:

setsebool -P httpd_can_network_connect=1 
+1

檢查的東西,如防火牆,了Suhosin/SELinux的百般阻撓的事,等等等等。 – 2014-11-24 15:11:14

+0

很確定錯誤13是一個權限的事情。仔細檢查PHP中的密碼以確保? – rjdown 2014-11-24 15:13:57

+0

爲什麼你在這一行有一個反斜槓 - 'new \ mysqli('111.11'? – 2014-11-24 15:14:05

回答

3

客戶端環境問題 - Selinux在Centos中。 命令FO修復:

setsebool -P httpd_can_network_connect=1 
+0

非常感謝! – 2016-10-16 08:48:13