2016-11-16 94 views
0

你好我有我的本地計算機的問題。我安裝fedora和我有問題通過PHP連接到我的遠程MySQL服務器。通過php遠程mysql數據庫

PHP代碼:

$servername = "my_own_ip"; 
$username = "test"; 
$password = "test"; 
$dbname = "test"; 

$link = mysql_connect($servername, $username, $password); 
if (!$link) { 
    die('Could sdf connect: ' . mysql_error()); 
} 

echo 'Connected successfully'; 

$servername = "my_own_ip"; 
$username = "test"; 
$password = "test"; 
$dbname = "test"; 

// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 

$sql = "SELECT id, firstname, lastname FROM MyGuests"; 
$result = $conn->query($sql); 

if ($result->num_rows > 0) { 
    // output data of each row 
    while($row = $result->fetch_assoc()) { 
     echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; 
    } 
} else { 
    echo "0 results"; 
} 
$conn->close(); 

我敢肯定,我的服務器是正確配置,因爲我之前測試了Ubuntu的,現在我這個測試劇本上:

http://phpfiddle.org/

並正常工作。我認爲這是Fedora系統的一個問題,你能幫助我嗎?

+0

你可以在審計中看到什麼AVC? – Jakuje

+0

運行此腳本時會得到哪個錯誤? @Yuval Pruss – nivhanin

+0

這個問題的答案可能會用到你全部 - > http://stackoverflow.com/questions/15169458/how-to-connect-to-remote-mysql-database-using-php-hosted-on-dotcloud –

回答

0

這可能是幾個問題:

  • 也許你有一個網絡發出─嘗試發送ping命令要連接到服務器。
  • 也許你的fedora的防火牆是打開的。關閉它:

    $ systemctl禁用firewalld

做,當你運行該腳本,你找哪家錯誤?

+0

我幫你評論問題(沒有足夠的代表) – nivhanin