您好我的本地计算机有问题。我安装Fedora,我有问题通过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系统的一个问题,你能帮助我吗?
答案 0 :(得分:0)
可能有几个问题:
也许你的fedora的防火墙已经开启了。把它关掉:
$ systemctl disable firewalld
运行此脚本时会出现哪个错误?