Cant Connect to my MySql Database

Website

http://my-test-website.infinityfreeapp.com/test.php

Error Message

Connection failed: php_network_getaddresses: getaddrinfo failed: Name or service not known

Other Information

Hi There,

I am trying to connect to my mysql database from my php script called test.php. I have tried both mysql hostname: sql110.epizy. com and sql110.infinityfree. com. The password is the one created when click the show/hide button.

I add spaces to the two hostname urls to bypass the topic posting system

<?php $servername = "sql110.epizy.com"; $username = "epiz_34272048"; $password = "YLGWNKxkuwCc"; // Create connection $conn = new mysqli($servername, $username, $password,"epiz_34272048_computer_store "); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; $conn->close(); ?>

Stop exposing credentials here like password !
Where is DB NAME ??
DB connection should like host name DB NAME DB USER DB PASS like this

4 Likes

epiz_34272048_computer_store is the DBNAME

Didnt realize this was a public from thought there was support ticket system.

Support ticket system is only for premium user!
If you want to support only from ticket system then upgrade your account to premium hosting!

Or If you want solution only (no matter where is comes from) then here someone will help you!

Great I can’t delete my post.

Well, you can change your password for a start

5 Likes

This is really unnecessary.
Admin does not provide premium hosting on his own (what you know about premium hosting is ifastnet ruled by someone else)
The forum exists so others can help the people who have issues + different users can look up the answers via the search feature here.


Can you try formatting your code to be more readable?

```

Code goes here

```

4 Likes
<?php 
$servername = "sql110.epizy.com"; 
$username = "epiz_randomNumbers"; 
$password = "cpanel password"; 

// Create connection
 $conn = new mysqli($servername, $username, $password,"epiz_34272048_computer_store "); 

// Check connection 
if ($conn->connect_error) 
{ 
          die("Connection failed: " . $conn->connect_error); 
}
 
echo "Connected successfully"; $conn->close(); 
?>

How I can.t find it. only the client area password one is all I can find.

You can change password here

3 Likes

Thanks,

Must be blind

1 Like

From the code you sent, it appears that you’ve put an extra space before closing the quotation marks around your database name, so that could be a reason why you are getting an error.

I am curious, why do you hardcode it in the connection instead of creating a variable like you have done with the other values?

2 Likes

I took a look at the actual code that’s on your site, and there is a small but critical difference between what’s in the file and what you’ve shared here.

Because the current content of line two is this:

    $servername = "sql110.infinityfree.com ";

At the end of the servername string is a trailing space. That may seem irrelevant, but when it comes to configuration, the value must be exactly the right one, and adding a space makes it a different value.

If you remove the space, it will fix this error.


Changing just this won’t also fix your database connection. The password in the config file is no longer correct because you already change the password of your account. And the password string also contains extra spaces, which will also break it.

Finally, you may also need to add the database name to the connect function. And as with the hostname and password: please make sure that no extra spaces are included.

5 Likes

Well the problem is solved but the issue was that somehow the ftp server wasnt saving my changes without telling me.

I already tried removing the extra spaces and including the dnmane I also tried the other sql hostname(the one in cpanel is different then the one in main mysql account tab). None of these worked because of the above mentioned bug that the ftp server wasn’t actually saving my changes to the file.

anyways thanks for everyone responding.

2 Likes

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