Mysqli_connect(): (HY000/2002): Connection refused

Username (e.g. epiz_XXX) and Website URL

epiz_31039179 (Website for dbi.rf.gd)

Error Message

Warning: mysqli_connect(): (HY000/2002): Connection refused in /home/vol1_3/epizy.com/epiz_31039179/htdocs/xxx.php on line 57

Warning: mysqli_error() expects parameter 1 to be mysqli, bool given in /home/vol1_3/epizy.com/epiz_31039179/htdocs/xxx.php on line 58

Other Information

I’ve seen this error message several times (maybe…over a month?) and switched the accounts for it.

Here are imformations:

Before I change account:
Username: epiz_29904250;
MySQL Hostname: sql212.epizy.com.
After I change account:
Username: epiz_31039179;
MySQL Hostname: sql211.epizy.com.

Line 57,58 on xxx.php:
57: $connect = mysqli_connect($dbhost, $dbuser, $dbpass);
58: if(!$connect){die('Died: ’ . mysqli_error($connect));}

By the way,I’m not a native English speaker, so excuse me if I make grammatical mistakes.( ̄ε(# ̄)

You need 4 variables, not three. You need to define the server, username, password, and table name.

$DataBase = array(
	"hostname" => "sql112.epizy.com",
	"username" => "epizy_2196992160",
	"password" => "password",
	"name" => "epizy_2196992160_tableName"
);
1 Like

You need to know basic PHP to connect to a database. Please refer to this:

Thanks…But I know it, here is the context:

function sql($sql)
{
	global $dbhost;
	global $dbuser;
	global $dbpass;
	global $dbname;
	
	$connect = mysqli_connect($dbhost, $dbuser, $dbpass);
	if(!$connect){die('Died: ' . mysqli_error($connect));}
	mysqli_query($connect , "set names utf8mb4");
	mysqli_select_db( $connect, $dbname );
	$retval = mysqli_query($connect,$sql);
	if(!$retval){die('Died: ' . mysqli_error($connect));}
	return $retval;
	mysqli_close($connect);
}

and this:

$dbhost = 'sql211.epizy.com';
$dbuser = 'epiz_31039179';
$dbpass = 'xxxxxxxxx';
$dbname = 'epiz_31039179_name';

You need all 4 variables.

$dbhost = 'sql211.epizy.com';
$dbuser = 'epiz_31039179';
$dbpass = 'xxxxxxxxx';
$dbname = 'epiz_31039179_name';
$conn = new mysqli($dbhost, $dbuser, $dbpass,$dbname) or die("Connect failed: %s\n". $conn -> error);

@jaikrishna.t, that article does not even have the correct steps. Please read it first before you post it

The fourth variable is here↑
It works fine on my computer!
The php code looks correct (o_o …)

No, when connecting to the database you need to state all variables at once. You may be able to connect to other databases using the code you have, but in order to connected to InfinityFree’s databases, you need to use all 4 in the mysqli_connect() command.

2 Likes

May be I didn’t describe it clearly, these codes can run normally in InfinityFree, but sometimes ran into this error.

Try using the code I shared. I can’t help you if you don’t try anything.

2 Likes

OK, I will try it, thanks (✿◡‿◡)

How often does this happen? A few times per month doesn’t sound so bad.

There are various reasons why this can occur. Maybe the database server is congested, maybe maintenance is being performed, maybe you’re running into a limit.

Please note that we can’t and don’t promise perfect uptime on free hosting.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.