Can't connect to MySQL server

I have created a database and I have a few files in the file manager which I am using to send a JSON response with info from the database.

My website URL is:
http://scuvo.epizy.com/get_articles.php

What I’m seeing is:
An error connecting to the database

I’m using a web browser to check for the desired JSON response. However it seems like the info that I have put in my db_connect.php does not connect to the database. I got the DBName, DBUserName, Port and MYSQL Host Name from the cPanel and I got the password from my accounts settings, the one that I use for my FTP as well, however I can’t seem to make a connection with the DB, why would that be? Please help, as I need this working ASAP

https://infinityfree.net/support/common-mysql-errors/

1 Like

I have this piece in my db_connect.php

%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5

and when I run the response file (http://scuvo.epizy.com/get_articles.php) I get the following:
** Warning : mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/vol15_6/epizy.com/epiz_24918691/htdocs/dbconnect.php on line 13

Warning : mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/vol15_6/epizy.com/epiz_24918691/htdocs/dbconnect.php on line 13
Connection successful!
Warning : mysqli_query(): Couldn’t fetch mysqli in /home/vol15_6/epizy.com/epiz_24918691/htdocs/get_articles.php on line 5
There was an error with the query!**

Which means that it connects to the db initially, but when I try to get the info from the DB it just denies it.

What value is $dbport?

Also, whenever I use the following site for checking db connection:
https://www.rainbowspuppiessunshine.com/tools/dbtest/index.php

I get this:

After using my ftp password (which seems to be the same as the one displayed in account details).
That would mean I can’t make a connection at all. Do I need to use some sort of VPN or something, in order to access the server?

3306 I saw it from my cpanel

FYI: this hosting doen’t allow DB Remote, Which means the site you tried to connect to the database cannot connect due this.

Can you try to connect without $dbport?

2 Likes

I removed the $dbport and the code is as follows:

$dbconnection = new mysqli($dbhost, $dbuser, $dbpassword, $db);

if($dbconnection){
echo(“Connection successful!”);
}
else{
echo("Connection failed " . mysql_error());
}
?>

But I still get the same response when I run my url

The following code makes the “couldn’t fetch” error:

$query = “SELECT * FROM articles”;

$result = mysqli_query($dbconnection, $query);

it seems like the mysqli_query command can’t fetch any data for some reason

Pro tip: use prepared statements, so that if someone puts other MySQL code, it won’t be executed: PHP MySQL Prepared Statements

I won’t have MySQL code input, as these are just JSON responses, so that won’t be an issue.

Apparently I am retarded, cuz in the name for the host I had an empty space … well wasted 2hrs making a new server response somewhere else and figuring that out.

1 Like

However now I get a HTTP1.1 403 Forbidden whenever I try to get the JSON in my Unity project. Is that cuz the db is not supposed to be public or is it something else?

https://infinityfree.net/support/javascript-error-using-api-or-mobile-android-app/

2 Likes

Thanks! and Yikes :x:

1 Like

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