"Error establishing a database connection" occurs randomly

Username: epiz_25296876
Website: https://shhsye.ml

Error Message

Warning : mysqli_real_connect(): (HY000/2002): Connection timed out in /home/vol7_8/epizy.com/epiz_25296876/htdocs/wp-includes/wp-db.php on line 1653

Deprecated : mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/vol7_8/epizy.com/epiz_25296876/htdocs/wp-includes/wp-db.php on line 1685

Warning : mysql_connect(): Connection timed out in /home/vol7_8/epizy.com/epiz_25296876/htdocs/wp-includes/wp-db.php on line 1685

Connection timed out

Other Information

I have tried reconfiguring the db username, password and hosting site in wp-config.php.

The problem only comes about randomly but it can last for a long time. Sometimes it works perfectly and then it doesn’t. It caused a lot of problems and I am afraid it can affect performance.

Can you help me out? I have already tried a lot of things and it is still not working.

It occurred after I added SSL to the website. I had to change the nameservers and maybe it is because of that? The db name and hosting site were different from the ones in cpanel so I changed it to that but the problem still persisted. Or is it caused by the SSL?

Any help is appreciated, thanks!

Firstly, make sure your using the MySQLi library, not the MySQL library (difference is the i at the end) as that will cause you issues.

As for your actual problem, might I ask what Database details you are using (do not show your password).

It may be that your issue is caused by the recent outages, and in that case, the only thing you can do is wait.

3 Likes

I tried my best to check it but I don’t know how to go about checking it. Can you help me with it?

I went to the MySQL in the cpanel and pressed ADMIN on the database but I don’t know where to look to see if it MySQLi Library.

Originally it was sql200.byetcluster.com, with the login details being different from the one stated on the cpanel’s MySQL Databases.

I changed it to sql200.epizy.com with the login details in the picture below when the problem occurred.

I did check if the details that I changed was correct. And also if the db name was the same one as one of the four databases.

2 posts were split to a new topic: Temporary topic (by MOD) until the user fills out the template

The difference is in you code, you should have something like this:

$mysqli = new mysqli(host, user, pass, db);


Can you share the code that your using on your website?

2 Likes

Yes, but which one specifically? I can’t seem to find one that is specific to the code you mentioned… Sorry.

if ( $this->use_mysqli ) {
		$this->dbh = mysqli_init();

		$host    = $this->dbhost;
		$port    = null;
		$socket  = null;
		$is_ipv6 = false;

		$host_data = $this->parse_db_host( $this->dbhost );
		if ( $host_data ) {
			list( $host, $port, $socket, $is_ipv6 ) = $host_data;
		}

		/*
		 * If using the `mysqlnd` library, the IPv6 address needs to be enclosed
		 * in square brackets, whereas it doesn't while using the `libmysqlclient` library.
		 * @see https://bugs.php.net/bug.php?id=67563
		 */
		if ( $is_ipv6 && extension_loaded( 'mysqlnd' ) ) {
			$host = "[$host]";
		}

		if ( WP_DEBUG ) {
			mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
		} else {
			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
			@mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
		}

		if ( $this->dbh->connect_errno ) {
			$this->dbh = null;

			/*
			 * It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
			 *  - We haven't previously connected, and
			 *  - WP_USE_EXT_MYSQL isn't set to false, and
			 *  - ext/mysql is loaded.
			 */
			$attempt_fallback = true;

			if ( $this->has_connected ) {
				$attempt_fallback = false;
			} elseif ( defined( 'WP_USE_EXT_MYSQL' ) && ! WP_USE_EXT_MYSQL ) {
				$attempt_fallback = false;
			} elseif ( ! function_exists( 'mysql_connect' ) ) {
				$attempt_fallback = false;
			}

			if ( $attempt_fallback ) {
				$this->use_mysqli = false;
				return $this->db_connect( $allow_bail );
			}
		}
	} else {
		if ( WP_DEBUG ) {
			$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
		} else {
			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
			$this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
		}
	}

I did find this that had similar codes to the one you mentioned.

This is the database details (I hope)

define( 'DB_NAME', 'epiz_25296876_____' );

/** MySQL database username */
define( 'DB_USER', 'epiz_25296876' );

/** MySQL database password */
define( 'DB_PASSWORD', 'afakepass' );

/** MySQL hostname */
define( 'DB_HOST', 'sql200.epizy.com' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8m__' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
1 Like

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