I am setting a new live server for my Laravel application its work perfectly on localhost
but not on live server. Now its showing SQL State [2002] connection refused
. I also try with mysqli_connect and PDO but the error remains the same. Is possible a problem with Hosting Provider?
<?php
$servername = "examrunner.com";
$database = "XXXXXXXX";
$username = "XXXXXXX";
$password = "XXXXXXXXXX";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
2
Answers
Use server name as localhost. Because cPanel hosts your databases locally, use localhost as the database’s hostname.
Please check below mentioned points to resolve this issue :
Check database and user exists
Make sure that Database user and Database connected to each other and you have given sufficient privileges to user.
If site hosted on current serve user hostname = ‘localhost’
Try to print detailed error.