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的,現在我這個測試劇本上:
並正常工作。我認爲這是Fedora系統的一個問題,你能幫助我嗎?
你可以在審計中看到什麼AVC? – Jakuje
運行此腳本時會得到哪個錯誤? @Yuval Pruss – nivhanin
這個問題的答案可能會用到你全部 - > http://stackoverflow.com/questions/15169458/how-to-connect-to-remote-mysql-database-using-php-hosted-on-dotcloud –