skip to Main Content

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


  1. Use server name as localhost. Because cPanel hosts your databases locally, use localhost as the database’s hostname.

    $servername   = "localhost";
    
    Login or Signup to reply.
  2. Please check below mentioned points to resolve this issue :

    1. Check database and user exists

    2. Make sure that Database user and Database connected to each other and you have given sufficient privileges to user.

    3. If site hosted on current serve user hostname = ‘localhost’

    4. Try to print detailed error.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search