After reading over a number of the similar topics here and on other various internet forums, I’m still having an issue with my PHP code which is throwing me for a loop… Here’s the error that the error_log
file is giving me:
[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
And here is the current, and very simple, state of my code:
<!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>
I’ve tried the following so far:
- Changing hostname between
localhost
,127.0.0.1
, and the server shared IP - Modifying the PHP socket to no avail, as I was unable to find the proper configuration to do so on CPanel
Additionally, some things to note are:
- I am doing this off of CPanel web hosting
- The database name, username, and password are all correct and linked to the database (Password covered for security)
2
Answers
check mysqld is running and that your firewall is allowing the mysql database through.
Edit your php.ini file and make sure extension extension=php_mysqli.dll is enabled on Windows or extension=php_mysqli.so on Linux.
Try the answer here: Test Mysql
you have MySQL server installed of course):
[mysqld] heading.
match the other and restart respective service.