Error 5000 when connecting database with .php file

Website URL

https://flymann-digital-solutions.rf.gd

Error Message

Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo for sql208.infinityfree.com failed: Name or service not known in /home/vol11_3/infinityfree.com/if0_36114137/htdocs/db_conn.php on line 11

Other Information

(other information and details relevant to your question)

Please see:

4 Likes

I had a quick look at your code, and I see the issue.

You’ve written the database hostname (as well as all other credentials), like this:

$db_host = "
sql208.infinityfree.com";

By writing it like this, you introduce an additional newline character before the actual hostname. And \nsql208.infinityfree.com is not the same as sql208.infinityfree.com, and the former will not work.

I would suggest putting the setting on a single line, like so:

$db_host = "sql208.infinityfree.com";

If you do insist on having it on multiple lines, then you should put the quote on the next line too, like:

$db_host = 
"sql208.infinityfree.com";

This also goes for any whitespace or newlines after variable contents (like is the case with the database name).


And this also applies to using the variables elsewhere. You’re establishing the database connection like this:

$conn = mysqli_connect(
"$db_host", "$db_username", "$db_pass
","$db_name
");

By having all the quotes and newlines here, you’re adding additional whitespace characters at the end of the password and database name, which will break your connection again, even if you created the variables correct.

And you don’t even need to reformat your code for this. Just remove the quotes and this code will work. There are only downsides to adding the additional quotes. Just pass the variables into the code as variables.

11 Likes

Woked. :white_check_mark:
Thankful.

2 Likes

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