Can't connect to the db using PHP

Hi everyone,

I’m trying to connect my simple PHP website to my MySQL database on InfinityFree using the following db.php code:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);


$host = 'sql100.infinityfree.com'; 
$user = 'if0_38872548';           
$pass = 'xxxxxxx';         
$db   = 'if0_38872548_test';   

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

if ($conn->connect_error) {
    echo "<strong>Fout:</strong> " . $conn->connect_error;
} else {
    echo "✅ Connected";
}
?>

But I keep getting this error:

“Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo for sql100.infinityfree.com failed: Name or service not known in /home/stanson/public_html/db.php on line 11”

What I’ve tried so far:

  • Double-checked my credentials
  • Created a new database
  • Verified phpMyAdmin works and the DB is active
  • Enabled error reporting in PHP

Please note that our database servers can only be accessed by PHP code running on our servers. It’s not possible to connect to our database servers from elsewhere.

And the path of your code tells me it’s definitely not running on our servers.

I can’t tell exactly where it is running. If you’re trying to host it at another hosting provider, please see if they may have a MySQL database you an use instead. And if it’s for local development, maybe you can setup a local MySQL server too.

7 Likes