I have one shared Cpanel Hosting and one My own server with cpanel hosting. I am trying to connect from shared cpanel hosting to my own server for get data from my own server. I have added my shared cpanel hosting IP to my server cpanel in remote MySQL section but I am getting above error. I have also added that IP from WHM but not success. I have checked that port 3306 also open. I do not know whats issue. I have tried below connection type but same error always.
$SERVER_NAME = "195.201.XXX.XXX";
$USER_NAME = "MyUserName";
$PASSWORD = "MyPass";
$DATABASE = "Mydb";
$conn = mysqli_connect($SERVER_NAME, $USER_NAME, $PASSWORD, $DATABASE,"3306");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
I have also tried below code
$SERVER_NAME = "195.201.XXX.XXX";
$USER_NAME = "MyUserName";
$PASSWORD = "MyPass";
$DATABASE = "Mydb";
$conn = mysqli_connect($SERVER_NAME, $USER_NAME, $PASSWORD, $DATABASE);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
But I am getting error like this
Failed to connect to MySQL: Connection refused
and in error log like this
mysqli_connect(): (HY000/2002): Connection refused in
Let me know whats wrong with it and how can I solve it. Thanks