在阅读了这里和其他各种互联网论坛上的一些类似主题之后,我仍然遇到了我的PHP代码问题,这让我陷入了循环...这里出现了错误error_log
文件正在给我:
[30-Apr-2018 17:05:11 UTC] PHP Warning: mysqli::mysqli(): (HY000/2002): Connection refused in /home/nicktric/public_html/index.php on line 12
这是我当前的,非常简单的代码状态:
<!DOCTYPE html>
<html>
<body>
<?php
$servername = "127.0.0.1";
$username = "nicktric_admin";
$password = "########";
$dbname = "nicktric_routes";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name, server, status FROM routeStatus";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br> id: ". $row["name"]. " - Name: ". $row["server"]. " " . $row["status"] . "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
</body>
</html>
到目前为止,我已尝试过以下内容:
localhost
,127.0.0.1
和服务器共享IP 此外,需要注意的一些事项是:
答案 0 :(得分:0)
检查mysqld是否正在运行,并且防火墙允许通过mysql数据库。
编辑你的php.ini文件并确保在Windows上启用扩展名扩展名= php_mysqli.dll或在Linux上启用扩展名= php_mysqli.so。
在此处尝试答案:Test Mysql
答案 1 :(得分:0)
In /etc/mysql/my.cnf you should see this near the top of the file:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
Change socket to the location of your MemSQL socket file. By default, this is /var/lib/memsql/data/memsql.sock.
hope that will work !