Unknown MySQL server host (PHP)

Unknown MySQL server host (PHP)

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Unknown MySQL server host (PHP)

The error Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2005): Unknown MySQL server host 'xxxxxxxxxxxxx:port' is a network-level failure, not an application logic bug. It indicates that the PHP process cannot resolve the provided hostname string into a valid IP address or establish a TCP connection to it. When you see this error on line 18 of your index.php, the issue almost certainly lies in how the $db_host variable is constructed relative to your hosting environment, specifically with providers like 1&1 IONOS.

The most common cause for this specific error message is a malformed host string. In your code snippet, you are passing $db_host directly to the constructor. If that variable contains a value like "xxxxxxxxxxxxx:port", PHP's underlying C library attempts to parse this immediately. Standard MySQL drivers expect either an IP address (e.g., 192.168.1.1) or a resolvable hostname (e.g., db.example.com).

If your $db_host variable literally includes the port number concatenated directly to the hostname without a protocol prefix or separator that the specific MySQL client library expects, it fails DNS resolution. For instance, passing hostname:3306 usually works because the driver strips the port. However, if the variable is set to something like user@host:port (which is valid for some drivers but not others) or if the hostname itself is a bare domain that doesn't resolve in your specific network context, you get HY000/2005.

With shared hosting providers like 1&1 IONOS, DNS resolution often behaves differently than on a local machine. The error suggests that from your PHP server's perspective, the name xxxxxxxxxxxxx does not exist in the DNS zone it is querying. This frequently happens when using the wrong hostname for a managed database service. You might be trying to connect to a public IP or a hostname intended for external access while your application is running on a subdomain that has strict DNS isolation.

Consider how you are initializing the connection:

$this->db = new mysqli($db_host, $db_user, $db_psw, $db_name);

Ensure that $db_host contains exactly what was provided in your database credentials panel. If 1&1 provides a hostname like yourusername.mysql.database.azure.com, use that exact string. Do not append ports manually unless the credential panel explicitly instructs you to do so within the hostname variable itself, although standard practice is usually mysqli_connect(host, user, pass, db) where host is just host:port if the port differs from 3306.

Another frequent pitfall involves SSL configuration on modern database servers. If your hosting provider requires SSL for connections but your code does not specify it, some configurations might throw connection errors that look like host resolution failures, though usually, they are distinct (e.g., SSL connection error). However, if the hostname provided in your credentials is an internal address meant only for SSH tunneling or specific proxy usage, and you are trying to connect directly from the public web server without a tunnel, DNS will fail.

Check your .htaccess file or PHP configuration for any forced redirects or proxy settings that might alter the $_SERVER['HTTP_HOST'], though this rarely affects database connections directly. The primary focus must remain on the $db_host variable value. If you are unsure which hostname is correct, log into your hosting control panel (hPanel) and look at the "Database Management" section. There, you will often see two hostnames: one for local access (starting with yourusername) and one for external access.

If you are connecting from a different domain than the database server, ensure that your DNS records allow cross-domain resolution. Sometimes, using IP addresses instead of hostnames bypasses DNS issues entirely, provided firewall rules allow traffic on port 3306 or 3307 (if SSL is used). However, relying on IPs is often less secure and harder to manage if the server undergoes a migration.

For robust applications, consider implementing error handling that distinguishes between MYSQLI_HOSTINFO_UNREACHABLE and other connection errors. This helps in debugging whether the network path exists or if the credentials are simply wrong. If you are moving away from raw mysqli to a higher-level abstraction like Laravel, ensure your .env file contains the correct database host without extra whitespace or protocol prefixes that the underlying driver might misinterpret.

Our network