在阅读了这里和其他各种互联网论坛上的一些类似主题之后,我仍然遇到一个问题,我的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之间的主机名此外,有些事项需要注意:
检查mysql是否正在运行,并且您的防火墙允许通过mysql数据库。
编辑你的php.ini文件并确保在Windows上启用扩展扩展名= php_mysqli.dll或在Linux上启用扩展名= php_mysqli.so。
试试这里的答案:Test Mysql
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 !