I am working with phpmyadmin version 4.4.15.7. DB server MariaDB 5.5.47 localhost via unix socket utf-8. Webserver apache 2.4.6. Php version 5.4.16. Originally this code worked well running with cpanel but recently I switched to vestacp running .9.8-16. connection credentials seem to be correct. Error is thrown after using mysqli_connect function:
Failed to connect to MySQL: php_network_getaddresses: getaddrinfo failed: Name or service not known
Here is my php file--redacted a little for security purposes. The first echo statement is the one thrown.
<?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);
?>