2

I programmed a website in PHP that uses a MySQL Server through GoDaddy. I have the same code saved on my local computer and sync it with the directory on GoDaddy through an app. I also use XAMPP on my computer to test any changes I make to the website before I make the changes public. However, the localhost server is different and in no way connected with the cPanel GoDaddy server. Therefore, if something new is added to the database on the public server, I would have to

  1. Download the sql file on the remote phpmyadmin
  2. Upload this file on the localhost phpmyadmin

This is an inefficient process, so now I want to use PHP to connect to the GoDaddy server. To do this, I put the IP Address given to me in the GoDaddy hosting page as the host parameter of the mysqli_connect() function.

// Set the database access information as constants
define('DB_USER', 'libuc6kfb0jg');
define('DB_PASSWORD', 'MY PASSWORD');
define('DB_HOST', 'MY IP ADDRESS');
define('DB_NAME', 'firstborumdatabase');

This user has all privileges on both the remote and the localhost. On cPanel - Remote MySQL® I have added the IP Address of my computer's localhost server.

// Make the connection
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die('Could not connect to MySQL: ' . mysqli_connect_error());

When I put this code in, instead of having 'localhost' as my host, which connects to the local MySQL server of XAMPP, it gives the following error

Could not connect to MySQL: Access denied for user 'libuc6kfb0jg'@'[Sensitive Info]' (using password: YES)

Since I know it is not a permissions problem, the next thing I did was use the PORT parameter. So, I added 3306 to the end to no avail, for it gave me the same error. Lastly, I put in this code as a mysql command into the mysql client from the XAMPP Control Panel, and this gave me the same exact error.

Stack Overflow Research

Any help would be greatly appreciated.


Edit

I found a flaw: In cPanel, Remote MySQL Database, I added the IP Address that my localhost server is, not my computer's IP Address, if that makes sense. I am now changing the IP Address that I had added in this tool.

Marvin
  • 853
  • 2
  • 14
  • 38

1 Answers1

1

While giving the user all permissions is crucial for it to have the necessary access to your database that only affects the ability for him to manipulate the database. You need to also whitelist your computers IP with the Servers firewall or you will not be allowed to connect to the remote server.

  • How would I do this? On GoDaddy cPanel? – Marvin May 27 '19 at 18:52
  • https://www.godaddy.com/help/website-security-ip-access-control-27422 This is a link from Godaddy on how to whitelist IP's on your server. I hope this helps. – Julian Dasilva May 27 '19 at 18:53
  • This seems like the right thing, except I don't see Website Security anywhere – Marvin May 27 '19 at 18:56
  • I believe I have to purchase Website Security – Marvin May 27 '19 at 19:01
  • I believe you mentioned having access to CPanel. GoDaddy generally provides a lot of neat tools to help less experienced tech users manage to edit and modify components on their webserver. That link seems to teach you how to use those tools, but if its not working you can try to use the CPanel directly. Try the following steps" Find the databases section of your Cpanel. Select REMOTE Sql/Database/Mysql (May be different depending on your version of cpanel) Enter your development computers IP address (remember not to share this on Stack Overflow). Then hit submit. – Julian Dasilva May 27 '19 at 19:06
  • It's possible your whitelist may not have actually been applied. Sometiems these require a firewall/server restart. have You done this since applying all of your changes? – Julian Dasilva May 27 '19 at 19:19
  • Great glad I could help :) Happy coding. – Julian Dasilva May 27 '19 at 19:22
  • There seems to be slight delay when moving from page to page on localhost. Is this normal? – Marvin May 27 '19 at 19:23
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/194021/discussion-between-julian-dasilva-and-marvin). – Julian Dasilva May 27 '19 at 19:24