0
我正在使用phpmyadmin版本4.4.15.7。 DB服务器MariaDB 5.5.47本地主机通过unix套接字utf-8。 Webserver apache 2.4.6。 Php版本5.4.16。本来这个代码运行得很好,但最近我转向了运行.9.8-16的vestacp。连接凭证似乎是正确的。错误使用mysqli_connect功能后抛出:奇怪的MySQL连接错误
无法连接到MySQL:php_network_getaddresses:的getaddrinfo 失败:姓名或不知道
这里的服务是我的PHP文件 - 节录一点点出于安全目的。第一个echo语句是抛出的。
<?php
$sql = "SELECT * FROM Staff";
// Create connection
$con=mysqli_connect(‘localhost',’pil_pil’,’pass_password’,’db_db’);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}
// Close connections
mysqli_close($con);
?>
可能重复[php \ _network \ _getaddresses:getaddrinfo失败:名称或服务未知](http://stackoverflow.com/questions/2661546/php-network-getaddresses-getaddrinfo-failed-name-or-service不知道) –
非常感谢,但认为它必须与服务器配置的任何方式来解决这个问题? –
您可以使用其他mysql客户端从您的PHP服务器连接到数据库服务器吗? –