duanluanhui8348 2016-08-16 04:05
浏览 124

奇怪的MySQL连接错误

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);
?>
  • 写回答

1条回答 默认 最新

  • dtwk6019 2016-08-16 15:26
    关注

    Thank you for all the help guys. It appears to be working now. I don't know what happened. It may have been server side because I contacted the server admin. I think it may have been a dns transition phase from the cpanel dns and it just needed time. I didn't change any code on my part.

    评论

报告相同问题?

悬赏问题

  • ¥15 手机连接电脑热点显示无ip分配
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大